import { useState, useEffect } from 'react'; import { useSearchParams, Link } from 'react-router-dom'; export default function VerifyEmail() { const [searchParams] = useSearchParams(); const token = searchParams.get('token'); const [status, setStatus] = useState('verifying'); // verifying, success, failed, invalid const [message, setMessage] = useState(''); useEffect(() => { if (!token) { setStatus('invalid'); return; } const verify = async () => { try { const res = await fetch(`/api/auth/verify-email?token=${encodeURIComponent(token)}`); const data = await res.json(); if (res.ok && (data.message === 'verified' || data.message === 'already_verified')) { setStatus('success'); setMessage(data.message === 'already_verified' ? 'Already Verified' : 'Email Verified!'); } else { setStatus('failed'); setMessage(data.detail || 'This link is invalid or has expired.'); } } catch (err) { console.error(err); setStatus('failed'); setMessage('Could not connect to the server. Please try again later.'); } }; verify(); }, [token]); return (
Verifying your secure portal identity to protect client confidentiality and tax documents.
Please wait a moment while we authorize your credentials.
> )} {status === 'invalid' && ( <>
This verification link is missing a token.
Please use the link from your registration email.
{message === 'Already Verified' ? 'Your email is already verified. You can sign in below.' : 'Your email has been verified. You can now access your login portal.'}
Sign In to Portal > )} {status === 'failed' && ( <>{message}
Request New Link > )}