diff --git a/web/src/app/(main)/system/logs/page.tsx b/web/src/app/(main)/system/logs/page.tsx index d0578ba1..db21e880 100644 --- a/web/src/app/(main)/system/logs/page.tsx +++ b/web/src/app/(main)/system/logs/page.tsx @@ -2,6 +2,8 @@ import * as React from "react"; +import { toast } from "sonner"; + import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { t } from "@/i18n"; @@ -150,6 +152,9 @@ export default function LogsPage() { }); } setHasMore(data.has_more ?? false); + } catch (reason) { + // A 403 ForbiddenError carries the server message; a network failure carries its own. + toast.error((reason as Error)?.message ?? String(reason)); } finally { setLoadingHistory(false); } diff --git a/web/src/lib/api-fetch.ts b/web/src/lib/api-fetch.ts index 23b3137a..d0c06341 100644 --- a/web/src/lib/api-fetch.ts +++ b/web/src/lib/api-fetch.ts @@ -50,6 +50,8 @@ export async function apiFetch(path: string, init?: RequestInit): Promise | undefined), diff --git a/web/src/lib/auth.ts b/web/src/lib/auth.ts index 6c6736d1..ab8b3d67 100644 --- a/web/src/lib/auth.ts +++ b/web/src/lib/auth.ts @@ -10,13 +10,19 @@ export interface CurrentUser { role: string; } +// clearTokenCookie expires the route-guard cookie with the same attributes +// setToken uses, so every path that ends a session leaves no cookie behind. +function clearTokenCookie(): void { + const secure = window.location.protocol === "https:" ? "; Secure" : ""; + document.cookie = `${TOKEN_KEY}=; path=/; max-age=0; SameSite=Lax${secure}`; +} + // clearSession ends the session after the API answered 401: it drops the // stored token and the route-guard cookie and sends the browser to /login. export function clearSession(): void { if (typeof window === "undefined") return; localStorage.removeItem(TOKEN_KEY); - const secure = window.location.protocol === "https:" ? "; Secure" : ""; - document.cookie = `${TOKEN_KEY}=; path=/; max-age=0; SameSite=Lax${secure}`; + clearTokenCookie(); window.location.href = "/login"; } @@ -39,7 +45,7 @@ export const auth = { clearToken(): void { localStorage.removeItem(TOKEN_KEY); - document.cookie = `${TOKEN_KEY}=; path=/; max-age=0`; + clearTokenCookie(); }, // Parse the current user from the JWT payload's sub field; display only, no signature verification.