Fix 401 redirect loop on login page

The 401 handler was redirecting to /login unconditionally, causing an
infinite reload loop when useTheme fired unauthenticated API calls on
the login page itself. Now only redirects if not already on /login.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
curo1305
2026-04-18 21:16:45 +02:00
parent 75b7ae6062
commit 05d79d3d21
+3 -2
View File
@@ -58,8 +58,9 @@ async function request<T>(
// Global 401 handler — expired or invalid token
if (response.status === 401) {
localStorage.removeItem("token");
window.location.href = "/login";
// Throw so callers don't try to process the response
if (window.location.pathname !== "/login") {
window.location.href = "/login";
}
throw new ApiError(401, "Session expired");
}