import { useState } from 'react' import { useLoaderData, Navigate } from 'react-router-dom' import { getEmailVerification, verifyEmail } from '../lib/allauth' import Button from '../components/Button' export async function loader ({ params }) { const key = params.key const resp = await getEmailVerification(key) return { key, verification: resp } } export default function VerifyEmail () { const { key, verification } = useLoaderData() const [response, setResponse] = useState({ fetching: false, content: null }) function submit () { setResponse({ ...response, fetching: true }) verifyEmail(key).then((content) => { setResponse((r) => { return { ...r, content } }) }).catch((e) => { console.error(e) window.alert(e) }).then(() => { setResponse((r) => { return { ...r, fetching: false } }) }) } if ([200, 401].includes(response.content?.status)) { return } let body = null if (verification.status === 200) { body = ( <>

Please confirm that {verification.data.email} is an email address for user {verification.data.user.str}.

) } else if (!verification.data?.email) { body =

Invalid verification link.

} else { body =

Unable to confirm email {verification.data.email} because it is already confirmed.

} return (

Confirm Email Address

{body}
) }