'use client'; import { useState, type FormEvent } from 'react'; import { useRouter } from 'next/navigation'; import { signIn } from 'next-auth/react'; export function LoginForm() { const router = useRouter(); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); async function handleSubmit(e: FormEvent) { e.preventDefault(); const form = e.currentTarget; const email = (form.elements.namedItem('email') as HTMLInputElement).value; const password = (form.elements.namedItem('password') as HTMLInputElement).value; setBusy(true); setError(null); try { const result = await signIn('credentials', { email, password, redirect: false }); if (result?.error) { setError('Email ou password incorretos. Tente novamente.'); } else { router.push('/maintenance'); router.refresh(); } } catch { setError('Erro inesperado. Tente novamente.'); } finally { setBusy(false); } } return (
{error &&

{error}

}
); }