1import { useState } from 'react';
2import { useSearchParams } from 'react-router-dom';
3import PublicLayout from '../components/Layout/PublicLayout';
4import { apiFetch } from '../lib/api';
6export default function VerifyEmail() {
7 const [params] = useSearchParams();
8 const token = params.get('token') || '';
9 const [status, setStatus] = useState('idle'); // idle | ok | error
10 const [message, setMessage] = useState('');
12 async function handleVerify() {
15 const res = await apiFetch('/users/verify-email', {
17 headers: { 'Content-Type': 'application/json' },
18 body: JSON.stringify({ token })
20 const data = await res.json().catch(()=>({}));
21 if (!res.ok) throw new Error(data.error || 'Verification failed');
23 setMessage('Email verified successfully. You can close this page.');
26 setMessage(err.message || 'Failed to verify');
32 <div style={{ maxWidth: 600, margin: '3rem auto', padding: '2rem', background: '#fff', borderRadius: 12, boxShadow: '0 8px 24px rgba(0,0,0,0.08)' }}>
34 {status === 'idle' && (
36 <p>Click the button below to verify your email address.</p>
37 <button onClick={handleVerify}>Verify</button>
40 {status === 'loading' && <p>Verifying…</p>}
41 {status !== 'idle' && <p>{message}</p>}