added cli parameter to toggle registraion, and split the monorepo: now this is only the backend
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user