|
|
|
import React from 'react'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import Head from 'next/head'
|
|
|
|
import Router from 'next/router'
|
|
|
|
import isEmail from 'validator/lib/isEmail'
|
|
|
|
|
|
|
|
import {FormController, Input, Button} from '~/components/form'
|
|
|
|
import useAccountRedirect from '~/hooks/useAccountRedirect'
|
|
|
|
|
|
|
|
export default function Login(){
|
|
|
|
useAccountRedirect()
|
|
|
|
|
|
|
|
const redirectAfterLogin = user => {
|
|
|
|
if (user.is_admin)
|
|
|
|
Router.push('/admin')
|
|
|
|
else
|
|
|
|
Router.push('/account')
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Head>
|
|
|
|
<title>Login | Society of Socks</title>
|
|
|
|
</Head>
|
|
|
|
<FormController url="/api/auth" afterSubmit={redirectAfterLogin}>
|
|
|
|
<h1>Login</h1>
|
|
|
|
<Input label="Email" type="text" name="email" validate={value=>isEmail(value)} hint="Enter a valid email address" />
|
|
|
|
<Input label="Password" type="password" name="password" validate={value=>(value.length >= 8)} hint="Password must be at least 8 characters long" />
|
|
|
|
<Button type="submit">Submit</Button>
|
|
|
|
<p>Need an account? <Link href="/register"><a>Register here</a></Link>.</p>
|
|
|
|
</FormController>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|