From 08b782a48898ecd31ed4ad76ddb2e6ce3aac8c22 Mon Sep 17 00:00:00 2001 From: Marcos Reifonas Date: Tue, 18 Aug 2026 10:55:31 +0000 Subject: [PATCH] fix(auth): prevent concurrent token exchange in Logto callback during Strict Mode --- src/hooks/useAuth.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hooks/useAuth.tsx b/src/hooks/useAuth.tsx index e6c54ef..ae9e967 100644 --- a/src/hooks/useAuth.tsx +++ b/src/hooks/useAuth.tsx @@ -7,6 +7,7 @@ import React, { useEffect, useState, useCallback, + useRef, ReactNode, } from 'react'; import { supabase } from '@/integrations/supabase/client'; @@ -56,11 +57,15 @@ export function AuthProvider({ children }: { children: ReactNode }) { const [loading, setLoading] = useState(true); const [authInitialized, setAuthInitialized] = useState(false); const [isRecoveryFlow, setIsRecoveryFlow] = useState(false); + const callbackHandled = useRef(false); // Detecta callback URL e processa useEffect(() => { const url = new URL(window.location.href); if (url.searchParams.has('code')) { + if (callbackHandled.current) return; + callbackHandled.current = true; + setLoading(true); handleCallback().then((ok) => { if (ok) {