From 5dcdabbdfb4fc4f341575cc814276bddd1d71bff Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Sun, 12 Oct 2025 13:38:56 -0300 Subject: [PATCH] Make AuthService thread-safe and auto-create user --- src/bot/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bot/mod.rs b/src/bot/mod.rs index 5dc9bc39..ceb72b18 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -20,7 +20,7 @@ pub struct BotOrchestrator { pub session_manager: Arc>, tool_manager: Arc, llm_provider: Arc, - auth_service: AuthService, + auth_service: Arc>, pub channels: HashMap>, response_channels: Arc>>>, } @@ -36,7 +36,7 @@ impl BotOrchestrator { session_manager: Arc::new(Mutex::new(session_manager)), tool_manager: Arc::new(tool_manager), llm_provider, - auth_service, + auth_service: Arc::new(Mutex::new(auth_service)), channels: HashMap::new(), response_channels: Arc::new(Mutex::new(HashMap::new())), } @@ -215,6 +215,13 @@ impl BotOrchestrator { // Parse identifiers, falling back to safe defaults. let user_id = Uuid::parse_str(&message.user_id).unwrap_or_else(|_| Uuid::new_v4()); let bot_id = Uuid::parse_str(&message.bot_id).unwrap_or_else(|_| Uuid::nil()); + let mut auth = self.auth_service.lock().await; + let user_exists = auth.get_user_by_id(user_id)?; + + if user_exists.is_none() { + // User does not exist, invoke Authentication service to create them + auth.create_user("anonymous", "anonymous@local", "password")?; + } // Retrieve an existing session or create a new one. let session = {