fix(session): prevent false login state with userId=0
Addresses race condition and invalid state issues identified by Codex diagnostic:
1. CoreBridge: Add try_get() and is_initialized() methods to gracefully
handle uninitialized state instead of panicking
2. auth.rs: Use try_get() for V2 auth in login/auto_login/logout to
avoid panic if CoreBridge init is still in progress
3. LoginView.svelte: Reject userId=0 as fallback - if userInfo or userId
is missing/invalid, don't call onLoginSuccess (require re-login)
4. +page.svelte:
- Move get_audio_settings call to after sessionReady is set
- Add explicit userId > 0 check before activate_user_session
- Return early if activation fails to prevent sessionReady from
being set in broken state
These are tactical fixes aligned with ADR_RUNTIME_SESSION_CONTRACT.md
invariants. Full runtime state machine implementation to follow.
This commit is contained in:
1 parent
85757f186b
commit
c4b28e37ea
4 files changed
+60
-21
No files matched your search
@@ -92,11 +92,15 @@ pub async fn login(
|
||||
}
|
||||
|
||||
// Also authenticate V2 CoreBridge client for the new architecture
|
||||
let bridge = core_bridge.get().await;
|
||||
if let Err(e) = bridge.login(&email, &password).await {
|
||||
log::warn!("[Auth] V2 CoreBridge login failed (non-blocking): {}", e);
|
||||
// Use try_get() to gracefully handle case where CoreBridge init is still in progress
|
||||
if let Some(bridge) = core_bridge.try_get().await {
|
||||
if let Err(e) = bridge.login(&email, &password).await {
|
||||
log::warn!("[Auth] V2 CoreBridge login failed (non-blocking): {}", e);
|
||||
} else {
|
||||
log::info!("[Auth] V2 CoreBridge authenticated successfully");
|
||||
}
|
||||
} else {
|
||||
log::info!("[Auth] V2 CoreBridge authenticated successfully");
|
||||
log::warn!("[Auth] V2 CoreBridge not yet initialized, skipping V2 auth");
|
||||
}
|
||||
|
||||
Ok(LoginResponse {
|
||||
@@ -168,10 +172,11 @@ pub async fn logout(
|
||||
let client = state.client.read().await;
|
||||
client.logout().await;
|
||||
|
||||
// Also logout from V2 CoreBridge
|
||||
let bridge = core_bridge.get().await;
|
||||
if let Err(e) = bridge.logout().await {
|
||||
log::warn!("[Auth] V2 CoreBridge logout failed: {}", e);
|
||||
// Also logout from V2 CoreBridge (if initialized)
|
||||
if let Some(bridge) = core_bridge.try_get().await {
|
||||
if let Err(e) = bridge.logout().await {
|
||||
log::warn!("[Auth] V2 CoreBridge logout failed: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -263,11 +268,15 @@ pub async fn auto_login(
|
||||
}
|
||||
|
||||
// Also authenticate V2 CoreBridge client for the new architecture
|
||||
let bridge = core_bridge.get().await;
|
||||
if let Err(e) = bridge.login(&creds.email, &creds.password).await {
|
||||
log::warn!("[Auth/Auto] V2 CoreBridge login failed (non-blocking): {}", e);
|
||||
// Use try_get() to gracefully handle case where CoreBridge init is still in progress
|
||||
if let Some(bridge) = core_bridge.try_get().await {
|
||||
if let Err(e) = bridge.login(&creds.email, &creds.password).await {
|
||||
log::warn!("[Auth/Auto] V2 CoreBridge login failed (non-blocking): {}", e);
|
||||
} else {
|
||||
log::info!("[Auth/Auto] V2 CoreBridge authenticated successfully");
|
||||
}
|
||||
} else {
|
||||
log::info!("[Auth/Auto] V2 CoreBridge authenticated successfully");
|
||||
log::warn!("[Auth/Auto] V2 CoreBridge not yet initialized, skipping V2 auth");
|
||||
}
|
||||
|
||||
Ok(LoginResponse {
|
||||
|
||||
Reference in new issue
Block a user