added cli parameter to toggle registraion, and split the monorepo: now this is only the backend

This commit is contained in:
2026-01-13 16:04:58 +01:00
parent 0e8ef49cfd
commit 86d86473af
11 changed files with 184 additions and 146 deletions

View File

@@ -7,7 +7,7 @@ use axum::{
routing::{get, post, put},
};
use sqlx::PgPool;
use std::{env, sync::Arc};
use std::sync::Arc;
use uuid::Uuid;
use validator::ValidateEmail;
@@ -72,10 +72,12 @@ pub fn routes() -> Router {
.layer(axum::middleware::from_fn(registration_guard))
}
async fn registration_guard(req: Request, next: Next) -> Result<Response, StatusCode> {
if req.uri().path() == "/register"
&& env::var("CHATAPP_PROHIBIT_REGISTRATION").map_or(false, |v| v.to_lowercase() == "true")
{
async fn registration_guard(
Extension(config): Extension<Arc<AppConfig>>,
req: Request,
next: Next,
) -> Result<Response, StatusCode> {
if req.uri().path() == "/register" && config.prohibit_registration {
return Err(StatusCode::FORBIDDEN);
}
Ok(next.run(req).await)