mirror of
https://github.com/okieselbach/AutopilotMonitor.git
synced 2026-10-25 05:00:07 +00:00
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:
@@ -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]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user