From ad29cce6ac72805313aff54ca87b4a0f087103b6 Mon Sep 17 00:00:00 2001 From: Carlos Escalante Date: Tue, 9 Jun 2026 19:13:32 -0600 Subject: [PATCH] Skip 401 logout/redirect when already on the login page (FE-22) Co-Authored-By: Claude Fable 5 --- frontend/src/lib/api.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index f5d5849..fa95c22 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -46,8 +46,14 @@ async function request( }); if (res.status === 401) { - await fetch("/api/auth/logout", { method: "POST" }).catch(() => {}); - if (typeof window !== "undefined") window.location.replace("/login"); + // Don't logout/redirect from the login page itself — that would loop. + if ( + typeof window !== "undefined" && + !window.location.pathname.startsWith("/login") + ) { + await fetch("/api/auth/logout", { method: "POST" }).catch(() => {}); + window.location.replace("/login"); + } throw new ApiError(401, null); }