fix: проверка токена при загрузке batch3, ssr, admin
Все страницы теперь проверяют валидность токена через API при загрузке. Просроченный токен → refresh → если fail → redirect. Предотвращает "вечные сессии" на всех страницах. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+18
-2
@@ -94,8 +94,24 @@ button:disabled { background: var(--border); cursor: not-allowed; }
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) location.href = '/';
|
||||
let token = localStorage.getItem('token');
|
||||
// Validate token on load
|
||||
(async () => {
|
||||
if (!token) { location.href = '/'; return; }
|
||||
try {
|
||||
const r = await fetch('/api/history?limit=1', {headers:{'Authorization':'Bearer '+token}});
|
||||
if (r.ok) return;
|
||||
} catch {}
|
||||
const rt = localStorage.getItem('refresh_token');
|
||||
if (rt) {
|
||||
try {
|
||||
const r = await fetch('/api/refresh', {method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({refresh_token:rt})});
|
||||
if (r.ok) { const d = await r.json(); token = d.token; localStorage.setItem('token', token); return; }
|
||||
} catch {}
|
||||
}
|
||||
localStorage.removeItem('token'); localStorage.removeItem('refresh_token');
|
||||
location.href = '/';
|
||||
})();
|
||||
|
||||
let currentJobId = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user