Skip to content

Commit efd850f

Browse files
committed
fix(auth): clear token and safely redirect to login on 401
1 parent e7b44a1 commit efd850f

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

frontend/lib/api.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ async function fetchWithAuth<T>(baseUrl: string, endpoint: string, options?: Req
7474
cache: "no-store",
7575
});
7676
if (!res.ok) {
77-
// Do not auto-redirect on 401; surface the error so callers can decide.
77+
if (res.status === 401 && token) {
78+
clearToken();
79+
if (typeof window !== "undefined" && window.location.pathname !== "/login") {
80+
window.location.href = "/login";
81+
}
82+
}
7883
let detail;
7984
try {
8085
detail = await res.json();

frontend/tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)