From 85ee2b25494e08731df550e9c3d02711134478bb Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 30 Jul 2025 19:47:34 +0200 Subject: [PATCH] Ignore auto login variable if it is empty --- moneymgr_backend/src/app_config.rs | 12 ++++++++++-- moneymgr_backend/src/extractors/auth_extractor.rs | 2 +- moneymgr_backend/src/main.rs | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/moneymgr_backend/src/app_config.rs b/moneymgr_backend/src/app_config.rs index e9c764b..18cdc1b 100644 --- a/moneymgr_backend/src/app_config.rs +++ b/moneymgr_backend/src/app_config.rs @@ -29,7 +29,7 @@ pub struct AppConfig { /// Unsecure : for development, bypass authentication, using the account with the given /// email address by default #[clap(long, env)] - pub unsecure_auto_login_email: Option, + unsecure_auto_login_email: Option, /// PostgreSQL database host #[clap(long, env, default_value = "localhost")] @@ -148,9 +148,17 @@ impl AppConfig { &ARGS } + /// Get auto login email (if not empty) + pub fn unsecure_auto_login_email(&self) -> Option<&str> { + match self.unsecure_auto_login_email.as_deref() { + None | Some("") => None, + s => s, + } + } + /// Check if auth is disabled pub fn is_auth_disabled(&self) -> bool { - self.unsecure_auto_login_email.is_some() + self.unsecure_auto_login_email().is_some() } /// Get auth cookie domain diff --git a/moneymgr_backend/src/extractors/auth_extractor.rs b/moneymgr_backend/src/extractors/auth_extractor.rs index 68f163c..9e6b75a 100644 --- a/moneymgr_backend/src/extractors/auth_extractor.rs +++ b/moneymgr_backend/src/extractors/auth_extractor.rs @@ -182,7 +182,7 @@ impl FromRequest for AuthExtractor { } // Check if login is hard-coded as program argument - if let Some(email) = &AppConfig::get().unsecure_auto_login_email { + if let Some(email) = &AppConfig::get().unsecure_auto_login_email() { let user = users_service::get_user_by_email(email).map_err(|e| { log::error!("Failed to retrieve dev user: {e}"); ErrorPreconditionFailed("Unable to retrieve dev user!") diff --git a/moneymgr_backend/src/main.rs b/moneymgr_backend/src/main.rs index 319f631..58172f7 100644 --- a/moneymgr_backend/src/main.rs +++ b/moneymgr_backend/src/main.rs @@ -38,7 +38,7 @@ async fn main() -> std::io::Result<()> { db_connection::initialize_conn().expect("Failed to connect to PostgresSQL database!"); // Auto create default account, if requested - if let Some(mail) = &AppConfig::get().unsecure_auto_login_email { + if let Some(mail) = &AppConfig::get().unsecure_auto_login_email() { users_service::create_or_update_user(mail, "Anonymous") .await .expect("Failed to create default account!");