45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
|
|
'use client'
|
|||
|
|
|
|||
|
|
import {signIn} from 'next-auth/react'
|
|||
|
|
import {useRouter} from 'next/navigation'
|
|||
|
|
import {useState} from 'react'
|
|||
|
|
import AuthForm from '@/components/auth-form/index.js'
|
|||
|
|
import AuthAlert from '@/components/auth-form/auth-alert.js'
|
|||
|
|
|
|||
|
|
export default function LoginForm() {
|
|||
|
|
const router = useRouter()
|
|||
|
|
const [error, setError] = useState('')
|
|||
|
|
const [isOpen, setIsOpen] = useState(false)
|
|||
|
|
|
|||
|
|
const handleFormSubmit = async data => {
|
|||
|
|
const response = await signIn('credentials', {
|
|||
|
|
email: data.email,
|
|||
|
|
password: data.password,
|
|||
|
|
redirect: false
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
if (response?.error) {
|
|||
|
|
setError(response.error)
|
|||
|
|
setIsOpen(true)
|
|||
|
|
} else {
|
|||
|
|
router.push('/')
|
|||
|
|
router.refresh()
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return (
|
|||
|
|
<>
|
|||
|
|
{error && <AuthAlert isOpen={isOpen} setIsOpen={setIsOpen} message={error} severity='error' />}
|
|||
|
|
<AuthForm
|
|||
|
|
title='Connectez-vous à votre compte'
|
|||
|
|
buttonText='Se connecter'
|
|||
|
|
linkDescription='Vous n’avez pas de compte ?'
|
|||
|
|
linkText='S’inscrire'
|
|||
|
|
linkHref='/register'
|
|||
|
|
isRegister={false}
|
|||
|
|
onSubmit={handleFormSubmit}
|
|||
|
|
/>
|
|||
|
|
</>
|
|||
|
|
)
|
|||
|
|
}
|