From ef02ec569640d2d4e3530481ad26381b596e059d Mon Sep 17 00:00:00 2001 From: Oliver Kieselbach Date: Wed, 25 Feb 2026 12:13:34 +0100 Subject: [PATCH] fixed bug on login site --- src/Web/autopilot-monitor-web/contexts/AuthContext.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Web/autopilot-monitor-web/contexts/AuthContext.tsx b/src/Web/autopilot-monitor-web/contexts/AuthContext.tsx index 677593d5..2b45644a 100644 --- a/src/Web/autopilot-monitor-web/contexts/AuthContext.tsx +++ b/src/Web/autopilot-monitor-web/contexts/AuthContext.tsx @@ -1,6 +1,6 @@ "use client"; -import React, { createContext, useContext, useEffect, useState, useCallback } from 'react'; +import React, { createContext, useContext, useEffect, useState, useCallback, useRef } from 'react'; import { PublicClientApplication, AccountInfo, InteractionStatus } from '@azure/msal-browser'; import { MsalProvider, useMsal, useIsAuthenticated } from '@azure/msal-react'; import { msalConfig, loginRequest, apiRequest } from '@/lib/msalConfig'; @@ -49,6 +49,7 @@ function AuthProviderInternal({ children }: { children: React.ReactNode }) { const isAuthenticated = useIsAuthenticated(); const [user, setUser] = useState(null); const [isLoading, setIsLoading] = useState(true); + const isLoadingRef = useRef(true); const [isPreviewBlocked, setPreviewBlocked] = useState(false); const [previewMessage, setPreviewMessage] = useState(''); @@ -152,6 +153,7 @@ function AuthProviderInternal({ children }: { children: React.ReactNode }) { } else { setUser(null); } + isLoadingRef.current = false; setIsLoading(false); } }; @@ -160,14 +162,15 @@ function AuthProviderInternal({ children }: { children: React.ReactNode }) { // Fallback: if MSAL doesn't initialize within 3 seconds, set loading to false anyway const timeout = setTimeout(() => { - if (isLoading) { + if (isLoadingRef.current) { console.warn('[Auth] MSAL initialization timeout - setting isLoading to false'); + isLoadingRef.current = false; setIsLoading(false); } }, 3000); return () => clearTimeout(timeout); - }, [accounts, inProgress, fetchUserInfo, isLoading]); + }, [accounts, inProgress, fetchUserInfo]); /** * Initiates login flow