import Image from 'react-bootstrap/Image' import * as cookie from 'cookie' import { StaticLayout } from '@/components/layout' import { getGetServerSideProps } from '@/api/ssrApollo' import { useRouter } from 'next/router' import { useState, useEffect, useCallback } from 'react' import { Form, SubmitButton, MultiInput } from '@/components/form' import { emailTokenSchema } from '@/lib/validate' // force SSR to include CSP nonces export const getServerSideProps = getGetServerSideProps({ query: null }) export default function Email () { const router = useRouter() const [callback, setCallback] = useState(null) // callback.email, callback.callbackUrl const [signin, setSignin] = useState(false) useEffect(() => { setSignin(!!cookie.parse(document.cookie).signin) 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) params.set('email', callback.email.toLowerCase()) const url = `/api/auth/callback/email?${params.toString()}` router.push(url) }, [callback, router]) const buildMessage = () => { const email = callback?.email || 'your email address' return signin ? `if there's a match, a magic code will be sent to ${email}` : `a magic code has been sent to ${email}` } return (

Check your email

{buildMessage()}

pushCallback(token)} disabled={!callback} signin={signin} />
) } export const MagicCodeForm = ({ onSubmit, disabled, signin }) => { return (
{ onSubmit(values.token.toLowerCase()) // token is displayed in uppercase but we need to check it in lowercase }} > {signin ? 'login' : 'signup'} ) }