//Lib import { useForm } from 'react-hook-form'; import { signIn } from 'next-auth/react'; import { useState } from 'react'; import { SpinnerDotted } from 'spinners-react'; import { useRouter } from 'next/router'; import { authOptions } from './api/auth/[...nextauth]'; import { getServerSession } from 'next-auth/next'; //Components import Error from '../Components/UI/Error/Error'; export default function Login() { //Var const { register, handleSubmit, formState: { errors }, reset, } = useForm(); const router = useRouter(); //State const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(); //Functions const formSubmitHandler = async (data) => { setIsLoading(true); setError(null); const resultat = await signIn('credentials', { username: data.username, password: data.password, redirect: false, }); setIsLoading(false); if (resultat.error) { reset(); setError(resultat.error); setTimeout(() => setError(), 4000); } else { router.replace('/'); } }; return (