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
@@ -73,7 +73,9 @@
|
||||
clearTimeoutTimer();
|
||||
const userInfo = await invoke<{ user_name: string; subscription: string; subscription_valid_until?: string | null } | null>('get_user_info');
|
||||
const userId = await invoke<number | null>('get_current_user_id');
|
||||
if (userInfo && userId) {
|
||||
// CRITICAL: userId must be a valid positive number, never 0 or null
|
||||
// If we can't get a valid userId, the session is broken and we need to re-login
|
||||
if (userInfo && userId && userId > 0) {
|
||||
onLoginSuccess({
|
||||
userName: userInfo.user_name,
|
||||
userId,
|
||||
@@ -81,7 +83,9 @@
|
||||
subscriptionValidUntil: userInfo.subscription_valid_until ?? null,
|
||||
});
|
||||
} else {
|
||||
onLoginSuccess({ userName: 'User', userId: userId || 0, subscription: 'Active' });
|
||||
// Session is invalid - don't use userId=0 fallback, show login instead
|
||||
console.warn('[LoginView] Session invalid: userInfo or userId missing/invalid, requiring re-login');
|
||||
// Don't call onLoginSuccess with invalid userId - let the login flow continue
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user