fix: timeout 10s en AuthProvider — spinner no queda bloqueado si Supabase no responde
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,11 +18,24 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Timeout de seguridad: si Supabase no responde en 10s, desbloquear UI
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
setLoading((prev) => {
|
||||||
|
if (prev) console.error('Auth timeout: la sesión de Supabase no respondió en 10s')
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}, 10_000)
|
||||||
|
|
||||||
const unsubscribe = authService.onAuthStateChange((u) => {
|
const unsubscribe = authService.onAuthStateChange((u) => {
|
||||||
|
clearTimeout(timeout)
|
||||||
setUser(u)
|
setUser(u)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
})
|
})
|
||||||
return unsubscribe
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout)
|
||||||
|
unsubscribe()
|
||||||
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const signIn = useCallback(() => authService.signInWithGoogle(), [])
|
const signIn = useCallback(() => authService.signInWithGoogle(), [])
|
||||||
|
|||||||
Reference in New Issue
Block a user