diff --git a/src/lib/api.ts b/src/lib/api.ts index 511ef33..21f86c9 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -6,7 +6,7 @@ const API_BASE = process.env.NEXT_PUBLIC_API_URL || "https://team.uix.su"; function getToken(): string | null { if (typeof window === "undefined") return null; - return localStorage.getItem("token"); + return localStorage.getItem("tb_token"); } async function request(path: string, options: RequestInit = {}): Promise { @@ -19,6 +19,11 @@ async function request(path: string, options: RequestInit = {}): Promis const res = await fetch(`${API_BASE}${path}`, { ...options, headers }); if (!res.ok) { + if (res.status === 401 && typeof window !== "undefined") { + localStorage.removeItem("tb_token"); + window.location.href = "/login"; + throw new Error("Unauthorized"); + } const err = await res.json().catch(() => ({ error: res.statusText })); throw new Error(err.error || `HTTP ${res.status}`); } diff --git a/src/lib/ws.ts b/src/lib/ws.ts index f23e2cc..aa9cf07 100644 --- a/src/lib/ws.ts +++ b/src/lib/ws.ts @@ -19,7 +19,7 @@ class WSClient { get connected() { return this.ws?.readyState === WebSocket.OPEN; } connect() { - const token = localStorage.getItem("token"); + const token = localStorage.getItem("tb_token"); if (!token) return; const wsBase = process.env.NEXT_PUBLIC_WS_URL || "wss://team.uix.su";