"use client"; import { useState } from "react"; import { signIn } from "next-auth/react"; import { useRouter } from "next/navigation"; import { Box, Button, Field, Input, VStack, Text, Heading, } from "@chakra-ui/react"; export default function LoginPage() { const router = useRouter(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); setLoading(true); const result = await signIn("credentials", { email, password, redirect: false, }); setLoading(false); if (result?.error) { console.log(result?.error); setError("Invalid email or password"); } else { router.push("/"); } }; return ( Log in {error && {error}} Email setEmail(e.target.value)} /> Password setPassword(e.target.value)} /> ); }