// Verify — URL `/verify?token=…`. The landing the magic-link / email-verification // mail points at. On mount it consumes the token via POST // /auth/magic-link/callback: a valid token signs the user in (session cookie // set) and we redirect home; an invalid/expired one shows a retry path. The same // page doubles as the email-verification confirmation. import type { ReactNode } from 'react' import { useEffect, useState } from 'react' import type { PageMeta } from '@voltro/web' import { T } from '@voltro/i18n' import { AuthShell } from '../../components/AuthShell' import { AUTH_HOME } from '../../config' import { postAuth } from '../../lib/auth' import { nextFromLocation, tokenFromLocation } from '../../lib/redirect' import { getCatalog } from '../../locales' export const renderMode = 'static' as const export const meta = ({ locale }: { readonly locale: string }): PageMeta => ({ title: getCatalog(locale)['meta.verify.title'], }) type State = 'pending' | 'success' | 'failed' | 'noToken' export default function Verify(): ReactNode { const [state, setState] = useState('pending') useEffect(() => { const token = tokenFromLocation() if (!token) { setState('noToken'); return } void postAuth('/auth/magic-link/callback', { token }) .then((res) => { if (res.ok) { setState('success') window.location.assign(nextFromLocation(AUTH_HOME)) } else { setState('failed') } }) .catch(() => setState('failed')) }, []) return ( : null}> {state === 'pending' ?

: null} {state === 'success' ?

: null} {state === 'failed' ?

: null} {state === 'noToken' ?

: null}
) }