feat(web): add SessionWatcher component for session management and handle session expiration

This commit is contained in:
2026-03-11 17:08:52 +08:00
parent 7bd4e379de
commit f1932676be
4 changed files with 51 additions and 0 deletions

View File

@@ -10,6 +10,9 @@ async function apiFetch<T>(path: string, init?: RequestInit): Promise<T> {
credentials: "include",
});
if (!res.ok) {
if (res.status === 401 && typeof window !== "undefined") {
window.dispatchEvent(new CustomEvent("session:expired"));
}
const text = await res.text().catch(() => res.statusText);
throw new Error(`API ${path} failed (${res.status}): ${text}`);
}