"use client"; import { FormEvent, useState } from "react"; import { signIn } from "next-auth/react"; import type { Route } from "next"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; export function LoginForm() { const router = useRouter(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [pending, setPending] = useState(false); async function onSubmit(event: FormEvent) { event.preventDefault(); setError(null); setPending(true); const result = await signIn("credentials", { email, password, redirect: false }); setPending(false); if (!result || result.error) { setError("Invalid email or password"); return; } router.push("/dashboard" as Route); router.refresh(); } return (
{error ?

{error}

: null}
); }