Create login page
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
'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}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import {getServerSession} from 'next-auth'
|
||||||
|
import {redirect} from 'next/navigation'
|
||||||
|
import LoginForm from './form.js'
|
||||||
|
|
||||||
|
export default async function LoginPage() {
|
||||||
|
const session = await getServerSession()
|
||||||
|
|
||||||
|
if (session) {
|
||||||
|
redirect('/')
|
||||||
|
}
|
||||||
|
|
||||||
|
return <LoginForm />
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user