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)
|
||||
|
||||
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) => {
|
||||
clearTimeout(timeout)
|
||||
setUser(u)
|
||||
setLoading(false)
|
||||
})
|
||||
return unsubscribe
|
||||
|
||||
return () => {
|
||||
clearTimeout(timeout)
|
||||
unsubscribe()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const signIn = useCallback(() => authService.signInWithGoogle(), [])
|
||||
|
||||
Reference in New Issue
Block a user