import { useState } from "react" import { useRouter } from "next/router" export default function SignIn() { const [username, setUsername] = useState("") const [password, setPassword] = useState("") const [error, setError] = useState("") const [loading, setLoading] = useState(false) const router = useRouter() const handleSubmit = async (e) => { e.preventDefault() setError("") setLoading(true) try { const res = await fetch("/api/auth/signin", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }) }) const data = await res.json() if (res.ok && data.ok) { // Set session cookie document.cookie = `next-auth.session-token=${data.token}; path=/; SameSite=Lax` router.push("/dashboard") } else { setError(data.error || "Erro ao entrar") } } catch (err) { setError("Erro de conexão") } finally { setLoading(false) } } return (