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:
2026-05-28 00:43:28 -03:00
parent 180ba2abe7
commit 1bc80e190f

View File

@@ -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(), [])