Skip 401 logout/redirect when already on the login page (FE-22)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Carlos Escalante
2026-06-09 19:13:32 -06:00
parent bebd7b563e
commit ad29cce6ac

View File

@@ -46,8 +46,14 @@ async function request<T>(
});
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);
}