import { useState } from 'react'; import { signIn, signOut, getCsrfToken, useSession } from 'next-auth/react'; import { Formik, Field, ErrorMessage } from 'formik'; import * as Yup from 'yup'; import { useRouter } from 'next/router'; import Link from 'next/link' export default function SignIn({ csrfToken }) { const router = useRouter(); const [error, setError] = useState(null); const { data: session } = useSession() // console.log(session) if (session) { return ( <>

You are already Signed in, click on continue
Continue...

or : ) } return ( <> { const res = await signIn('credentials', { redirect: false, email: values.email, password: values.password, callbackUrl: `${window.location.origin}`, }); if (res?.error) { setError(res.error); } else { setError(null); } if (res.url) router.push(res.url); setSubmitting(false); }} > {(formik) => (
{error}
)}
); } // This is the recommended way for Next.js 9.3 or newer export async function getServerSideProps(context) { return { props: { csrfToken: await getCsrfToken(context), }, }; }