fix(auth): prevent concurrent token exchange in Logto callback during Strict Mode
This commit is contained in:
@@ -7,6 +7,7 @@ import React, {
|
|||||||
useEffect,
|
useEffect,
|
||||||
useState,
|
useState,
|
||||||
useCallback,
|
useCallback,
|
||||||
|
useRef,
|
||||||
ReactNode,
|
ReactNode,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { supabase } from '@/integrations/supabase/client';
|
import { supabase } from '@/integrations/supabase/client';
|
||||||
@@ -56,11 +57,15 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [authInitialized, setAuthInitialized] = useState(false);
|
const [authInitialized, setAuthInitialized] = useState(false);
|
||||||
const [isRecoveryFlow, setIsRecoveryFlow] = useState(false);
|
const [isRecoveryFlow, setIsRecoveryFlow] = useState(false);
|
||||||
|
const callbackHandled = useRef(false);
|
||||||
|
|
||||||
// Detecta callback URL e processa
|
// Detecta callback URL e processa
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
if (url.searchParams.has('code')) {
|
if (url.searchParams.has('code')) {
|
||||||
|
if (callbackHandled.current) return;
|
||||||
|
callbackHandled.current = true;
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
handleCallback().then((ok) => {
|
handleCallback().then((ok) => {
|
||||||
if (ok) {
|
if (ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user