diff --git a/src/beacon/components/providers/auth-provider.tsx b/src/beacon/components/providers/auth-provider.tsx index d2e8b1387a..ccddcc7005 100644 --- a/src/beacon/components/providers/auth-provider.tsx +++ b/src/beacon/components/providers/auth-provider.tsx @@ -8,6 +8,12 @@ import authService from '@/services/api-service'; function AuthEffect({ children }: { children: ReactNode }) { const { data: session, status } = useSession(); const [handoffProcessed, setHandoffProcessed] = useState(false); + const [isHandlingHandoff, setIsHandlingHandoff] = useState(() => { + if (typeof window !== 'undefined') { + return window.location.hash.includes('token='); + } + return false; + }); useEffect(() => { if (status === 'authenticated' && session) { @@ -29,11 +35,15 @@ function AuthEffect({ children }: { children: ReactNode }) { role: (rawUser as any).privilege || 'user', }); } + + if (isHandlingHandoff) { + setIsHandlingHandoff(false); + } } else if (status === 'unauthenticated') { authService.setToken(null); authService.setUserData(null); } - }, [session, status]); + }, [session, status, isHandlingHandoff]); useEffect(() => { if (handoffProcessed) return; @@ -50,9 +60,22 @@ function AuthEffect({ children }: { children: ReactNode }) { redirect: true, callbackUrl: callbackUrl, }); + } else { + setIsHandlingHandoff(false); } }, [handoffProcessed]); + if (isHandlingHandoff || (status === 'unauthenticated' && typeof window !== 'undefined' && window.location.hash.includes('token='))) { + return ( +