Files
konstitisyon.nu/app/login/form.js
T

52 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'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) {
if (response.error === 'CredentialsSignin') {
setError('E-mail ou mot de passe incorrect')
} else if (response.error === 'Configuration') {
setError('Une erreur sest produite, contactez ladministrateur !')
} else {
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 navez pas de compte ?'
linkText='Sinscrire'
linkHref='/register'
isRegister={false}
onSubmit={handleFormSubmit}
/>
</>
)
}