import { useEffect, useState } from 'react'; import { useSearchParams } from 'react-router'; const API_URL = import.meta.env.VITE_API_URL ?? 'https://api.t4t-gateway.com'; type Status = 'pending' | 'success' | 'already' | 'error'; export function meta() { return [{ title: 'Verify email · t4t Gateway' }]; } export default function Verify() { const [params] = useSearchParams(); const token = params.get('token'); const [status, setStatus] = useState('pending'); const [message, setMessage] = useState(null); useEffect(() => { if (!token) { setStatus('error'); setMessage('Missing verification token in URL.'); return; } (async () => { try { const res = await fetch(`${API_URL}/auth/email/verify`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token }), }); const body = await res.json(); if (!res.ok) { throw new Error(body?.message ?? body?.error ?? `Verify failed (${res.status})`); } setStatus(body.alreadyVerified ? 'already' : 'success'); } catch (err) { setStatus('error'); setMessage(err instanceof Error ? err.message : 'Unknown error'); } })(); }, [token]); return (
{status === 'pending' && ( <>

Verifying…

One moment.

)} {status === 'success' && ( <>

Email verified

Your 50 xBZZ welcome credit is being applied.

Continue to log in )} {status === 'already' && ( <>

Already verified

This email was verified previously. Nothing to do.

Log in )} {status === 'error' && ( <>

Verification failed

{message}

Back to sign up )}
); }