From 865410fc219645b96fafa54cf89e45383fe933cd Mon Sep 17 00:00:00 2001 From: Oliver Kieselbach Date: Fri, 27 Feb 2026 15:42:49 +0100 Subject: [PATCH] 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 --- .../components/ProtectedRoute.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Web/autopilot-monitor-web/components/ProtectedRoute.tsx b/src/Web/autopilot-monitor-web/components/ProtectedRoute.tsx index 05247165..6a1d4cca 100644 --- a/src/Web/autopilot-monitor-web/components/ProtectedRoute.tsx +++ b/src/Web/autopilot-monitor-web/components/ProtectedRoute.tsx @@ -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]);