"use client" import { signIn } from "next-auth/react"; // client function import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; export default function AuthLoginForm() { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); const router = useRouter(); const handleSubmit = async (e: React.SubmitEvent) => { // event object from form element e.preventDefault(); // stops default submission to send through the js instead setError(""); // clear state setIsSubmitting(true); try { const res = await signIn("credentials", { // sends to auth.js server endpoint selecting credentials provider and supplies obj argument which it passes into authorize function, returns the user email, password, redirect: false, // prevents auto redirect }); if (res.error || !res) { setError("Sign in failed"); } else { router.push("/"); // if signin function doesnt error } } catch { setError("Unable to sign in. Please try again.") } finally { setIsSubmitting(false); } } return ( <>
{error && (
{error}
)} {" "}
setEmail(e.target.value)} required />
setPassword(e.target.value)} required />
OR

Don't have an account?{" "} Sign Up

); }