From a514209ea8e72b447b1576328cc33cdd9b4ba0c3 Mon Sep 17 00:00:00 2001 From: anor Date: Mon, 30 Mar 2026 04:51:36 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=20=D1=82=D0=BE=D0=BA=D0=B5=D0=BD=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B5?= =?UTF-8?q?=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Раньше: если token есть в localStorage — сразу showChat(). Теперь: fetch /api/history → если 401 → tryRefresh → если fail → logout. Предотвращает "вечные сессии" с просроченным токеном. Co-Authored-By: Claude Opus 4.6 (1M context) --- static/chat.html | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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';