import { useQueryClient } from '@tanstack/react-query' import { useNavigate } from '@tanstack/react-router' import { useState } from 'react' import { LoginInput } from '../ui/LoginInput' import { SubmitButton } from '../ui/SubmitButton' import { throwIfError } from '@/data/api/_helpers' import { qk } from '@/data/query/keys' import { supabaseBrowser } from '@/data/supabase/client' export function ExternalLoginForm() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState(null) const [isLoading, setIsLoading] = useState(false) const qc = useQueryClient() const navigate = useNavigate({ from: '/login' }) const supabase = supabaseBrowser() const submit = async () => { setIsLoading(true) setError(null) try { const { error } = await supabase.auth.signInWithPassword({ email, password, }) throwIfError(error) qc.invalidateQueries({ queryKey: qk.session() }) qc.invalidateQueries({ queryKey: qk.auth }) await navigate({ to: '/dashboard', replace: true }) } catch (e: unknown) { const anyErr = e as any setError(anyErr?.message ?? 'No se pudo iniciar sesión') } finally { setIsLoading(false) } } return (
{ e.preventDefault() submit() }} > {error ?

{error}

: null} ) }