fix: token key mismatch (tb_token), 401→redirect to login
All checks were successful
Deploy Web Client / deploy (push) Successful in 33s
All checks were successful
Deploy Web Client / deploy (push) Successful in 33s
This commit is contained in:
parent
90deac3246
commit
5e02200510
@ -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<T = any>(path: string, options: RequestInit = {}): Promise<T> {
|
||||
@ -19,6 +19,11 @@ async function request<T = any>(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}`);
|
||||
}
|
||||
|
||||
@ -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";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user