persist last user_id for session restore across app restarts

Saves the active user_id to a flat-path file on activate_user_session
and clears it on deactivate_user_session (explicit logout). On startup,
if saved credentials and a last_user_id both exist, the per-user session
is restored before loading ToS acceptance or attempting auto-login.

This fixes the chicken-and-egg problem where ToS acceptance lived in the
per-user DB but was needed before login to allow auto-login.
This commit is contained in:
vicrodh committed 2026-02-06 00:37:52 -06:00
1 parent 03736ef8f2
commit b6d2e10471
4 files changed
+62 -6

No files matched your search

+17 -5
View File
@@ -86,13 +86,25 @@
return;
}
// Load ToS acceptance from Rust (persisted, survives app updates)
initStatus = 'Loading preferences...';
await loadTosAcceptance();
// Check for saved credentials and auto-login
// Check for saved credentials and last user session
initStatus = 'Checking saved credentials...';
const hasSavedCreds = await invoke<boolean>('has_saved_credentials');
const lastUserId = await invoke<number | null>('get_last_user_id');
// Restore per-user session before reading ToS or auto-login
if (hasSavedCreds && lastUserId) {
initStatus = 'Restoring session...';
try {
await invoke('activate_user_session', { userId: lastUserId });
console.log('Restored user session for', lastUserId);
} catch (e) {
console.warn('Failed to restore user session:', e);
}
}
// Load ToS acceptance from Rust (now available after session restore)
initStatus = 'Loading preferences...';
await loadTosAcceptance();
if (hasSavedCreds && get(qobuzTosAccepted)) {
initStatus = 'Logging in...';