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:
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user