fix(web): stay logged in when app initialisation fails after reload

boot() ran token validation and launchApp() inside the SAME try/catch, so ANY
error during app init (a failed calendar/event fetch, a render error) cleared
the token and bounced a validly-authenticated user to the login screen — the
"logged out on every F5" bug. Now /auth/me validates the token alone; launchApp()
runs outside that catch, so a data/render error can no longer log the user out.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Scarriffle
2026-07-06 21:22:33 +02:00
parent 343f7a5e7b
commit 572172c424

View File

@@ -23,14 +23,23 @@ async function boot() {
// Check if already logged in
const token = localStorage.getItem('token');
if (token) {
let authed = false;
try {
await api.get('/auth/me'); // validate token
await launchApp();
return;
await api.get('/auth/me'); // validate the TOKEN only
authed = true;
} catch (_) {
// The token is genuinely invalid/expired — clear it and show login.
localStorage.removeItem('token');
localStorage.removeItem('user');
}
if (authed) {
// Token is valid → stay logged in. launchApp() runs OUTSIDE the auth
// try/catch on purpose: a later data/render error inside app init must
// never bounce a validly-authenticated user back to the login screen
// (that was the "logged out on every reload" bug).
await launchApp();
return;
}
}
showScreen('login');