fix(auth): prevent concurrent token exchange in Logto callback during Strict Mode

This commit is contained in:
2026-08-18 10:55:31 +00:00
parent 337b397772
commit 08b782a488
+5
View File
@@ -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) {