diff --git a/static/chat.html b/static/chat.html index a8fa1ff..dedb427 100644 --- a/static/chat.html +++ b/static/chat.html @@ -180,7 +180,17 @@ function checkAdmin() { } // --- Init --- -if (token) { checkAdmin(); showChat(); } else showLogin(); +// Validate token on page load (don't trust localStorage blindly) +(async () => { + if (!token) { showLogin(); return; } + try { + const r = await fetch(API + '/api/history?limit=1', {headers: {'Authorization': 'Bearer ' + token}}); + if (r.ok) { checkAdmin(); showChat(); return; } + } catch {} + // Access token expired — try refresh + if (await tryRefreshToken()) { checkAdmin(); showChat(); } + else { logout(); showLogin(); } +})(); function showLogin() { document.getElementById('login-screen').style.display = 'flex';