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:
@@ -23,14 +23,23 @@ async function boot() {
|
|||||||
// Check if already logged in
|
// Check if already logged in
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
if (token) {
|
if (token) {
|
||||||
|
let authed = false;
|
||||||
try {
|
try {
|
||||||
await api.get('/auth/me'); // validate token
|
await api.get('/auth/me'); // validate the TOKEN only
|
||||||
await launchApp();
|
authed = true;
|
||||||
return;
|
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
|
// The token is genuinely invalid/expired — clear it and show login.
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
localStorage.removeItem('user');
|
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');
|
showScreen('login');
|
||||||
|
|||||||
Reference in New Issue
Block a user