fix: auto-logout on 401 so stale tokens don't leave frontend in broken state

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Your Name
2026-05-19 14:27:20 +03:00
parent 04ff1b012b
commit 76a9d4c1b3

View File

@@ -150,9 +150,7 @@ createApp({
this.users = [];
this.status = '';
this.error = '';
this.view = 'byAud';
// опционально: редирект на страницу логина
// window.location.href = '/login';
window.location.href = '/login';
},
authHeaders() {
const h = {};
@@ -162,6 +160,10 @@ createApp({
async fetchAuth(url, options = {}) {
const opt = { ...options, headers: { ...(options.headers||{}), ...this.authHeaders() } };
const res = await fetch(url, opt);
if (res.status === 401) {
this.logout();
return;
}
if (!res.ok) {
const text = await res.text();
throw new Error(`HTTP ${res.status}: ${text}`);