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