fix: remove timer-based redirect delay in ProtectedRoute

Replace the fragile setTimeout(500ms) with a deterministic guard:
wasAuthenticated.current already prevents spurious redirects during
MSAL's double handleRedirectPromise cycle. The real fix was setting
navigateToLoginRequestUrl: false in msalConfig. No timer needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Oliver Kieselbach
2026-02-27 15:42:49 +01:00
parent 97ca48f56a
commit 865410fc21
@@ -25,15 +25,11 @@ export function ProtectedRoute({ children, requireGalacticAdmin = false }: Prote
}
useEffect(() => {
// Only redirect if MSAL has fully settled (!isLoading) and we were never
// authenticated in this session. wasAuthenticated guards against transient
// isAuthenticated=false flips during MSAL's double handleRedirectPromise cycle.
if (!isLoading && !isAuthenticated && !wasAuthenticated.current) {
// Delay redirect slightly to let MSAL finish its double handleRedirectPromise
// settling cycle before deciding the user is truly unauthenticated.
const t = setTimeout(() => {
if (!wasAuthenticated.current) {
router.push("/");
}
}, 500);
return () => clearTimeout(t);
router.push("/");
}
}, [isAuthenticated, isLoading, router]);