2023-07-24 13:35:05 -05:00
|
|
|
import Image from 'react-bootstrap/Image'
|
2024-03-20 01:37:31 +01:00
|
|
|
import { StaticLayout } from '@/components/layout'
|
|
|
|
import { getGetServerSideProps } from '@/api/ssrApollo'
|
2025-02-04 01:41:01 +01:00
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import { useState, useEffect, useCallback } from 'react'
|
|
|
|
import { Form, SubmitButton, MultiInput } from '@/components/form'
|
|
|
|
import { emailTokenSchema } from '@/lib/validate'
|
2024-02-13 23:40:26 +01:00
|
|
|
|
|
|
|
// force SSR to include CSP nonces
|
|
|
|
export const getServerSideProps = getGetServerSideProps({ query: null })
|
2023-01-10 17:13:37 -06:00
|
|
|
|
|
|
|
export default function Email () {
|
2025-02-04 01:41:01 +01:00
|
|
|
const router = useRouter()
|
|
|
|
const [callback, setCallback] = useState(null) // callback.email, callback.callbackUrl
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setCallback(JSON.parse(window.sessionStorage.getItem('callback')))
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
// build and push the final callback URL
|
|
|
|
const pushCallback = useCallback((token) => {
|
|
|
|
const params = new URLSearchParams()
|
|
|
|
if (callback.callbackUrl) params.set('callbackUrl', callback.callbackUrl)
|
|
|
|
params.set('token', token)
|
2025-02-23 18:03:32 +01:00
|
|
|
params.set('email', callback.email.toLowerCase())
|
2025-02-04 01:41:01 +01:00
|
|
|
const url = `/api/auth/callback/email?${params.toString()}`
|
|
|
|
router.push(url)
|
|
|
|
}, [callback, router])
|
|
|
|
|
2023-01-10 17:13:37 -06:00
|
|
|
return (
|
2023-07-23 10:08:43 -05:00
|
|
|
<StaticLayout>
|
2023-01-10 17:13:37 -06:00
|
|
|
<div className='p-4 text-center'>
|
2024-03-04 21:00:28 -06:00
|
|
|
<video width='640' height='302' loop autoPlay muted preload='auto' playsInline style={{ maxWidth: '100%' }}>
|
|
|
|
<source src={`${process.env.NEXT_PUBLIC_ASSET_PREFIX}/cowboy-saloon.mp4`} type='video/mp4' />
|
|
|
|
<Image className='rounded-1 shadow-sm' width='640' height='302' src={`${process.env.NEXT_PUBLIC_ASSET_PREFIX}/cowboy-saloon.gif`} fluid />
|
|
|
|
</video>
|
2023-07-29 14:38:20 -05:00
|
|
|
<h2 className='pt-4'>Check your email</h2>
|
2025-02-04 01:41:01 +01:00
|
|
|
<h4 className='text-muted pt-2 pb-4'>a magic code has been sent to {callback ? callback.email : 'your email address'}</h4>
|
|
|
|
<MagicCodeForm onSubmit={(token) => pushCallback(token)} disabled={!callback} />
|
2023-01-10 17:13:37 -06:00
|
|
|
</div>
|
2023-07-23 10:08:43 -05:00
|
|
|
</StaticLayout>
|
2023-01-10 17:13:37 -06:00
|
|
|
)
|
|
|
|
}
|
2025-02-04 01:41:01 +01:00
|
|
|
|
|
|
|
export const MagicCodeForm = ({ onSubmit, disabled }) => {
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
initial={{
|
|
|
|
token: ''
|
|
|
|
}}
|
|
|
|
schema={emailTokenSchema}
|
|
|
|
onSubmit={(values) => {
|
|
|
|
onSubmit(values.token.toLowerCase()) // token is displayed in uppercase but we need to check it in lowercase
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<MultiInput
|
|
|
|
length={6}
|
|
|
|
charLength={1}
|
|
|
|
name='token'
|
|
|
|
required
|
|
|
|
autoFocus
|
|
|
|
groupClassName='d-flex flex-column justify-content-center gap-2'
|
|
|
|
inputType='text'
|
|
|
|
hideError // hide error message on every input, allow custom error message
|
|
|
|
disabled={disabled} // disable the form if no callback is provided
|
|
|
|
/>
|
|
|
|
<SubmitButton variant='primary' className='px-4' disabled={disabled}>login</SubmitButton>
|
|
|
|
</Form>
|
|
|
|
)
|
|
|
|
}
|