The web app grows its account surface: login (with next-redirect, unverified-hint + resend), signup (react-hook-form + shared Zod schemas, field-level api errors, closed-registration state fed by the new public GET /auth/registration), e-mail verification, forgot/reset password; a settings page with profile (locale applies immediately), password change, and active-session management; a Site-Admin page for instance name, default locale, and registration mode. AuthProvider holds /auth/me, applies the profile locale, and backs route guards (RequireAuth/RequireAnonymous/RequireSiteAdmin); the top bar gains a user menu. All strings ship in the new auth/settings namespaces (de+ en); the exception filter now preserves handler-specific error codes. Verified live: signup → Mailpit → verify → login → profile through the Vite proxy. Closes #16 Closes #17 Closes #18 Closes #19 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Link, useSearchParams } from 'react-router-dom';
|
|
|
|
import { apiPost } from '../../lib/api';
|
|
|
|
type VerifyState = 'pending' | 'success' | 'error';
|
|
|
|
export function VerifyEmailPage(): React.JSX.Element {
|
|
const { t } = useTranslation();
|
|
const [params] = useSearchParams();
|
|
const [state, setState] = useState<VerifyState>('pending');
|
|
const [email, setEmail] = useState('');
|
|
const [resent, setResent] = useState(false);
|
|
|
|
const token = params.get('token');
|
|
|
|
useEffect(() => {
|
|
if (!token) {
|
|
setState('error');
|
|
return;
|
|
}
|
|
apiPost('/auth/verify-email', { token })
|
|
.then(() => setState('success'))
|
|
.catch(() => setState('error'));
|
|
}, [token]);
|
|
|
|
if (state === 'pending') {
|
|
return (
|
|
<div className="auth-card">
|
|
<h1>{t('auth:verify.title')}</h1>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (state === 'success') {
|
|
return (
|
|
<div className="auth-card">
|
|
<h1>{t('auth:verify.success.title')}</h1>
|
|
<p>{t('auth:verify.success.body')}</p>
|
|
<Link className="button" to="/login">
|
|
{t('auth:verify.success.login')}
|
|
</Link>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="auth-card">
|
|
<h1>{t('auth:verify.error.title')}</h1>
|
|
<p>{t('errors:token_invalid')}</p>
|
|
{resent ? (
|
|
<p className="form-banner form-banner--ok">{t('auth:verify.resent')}</p>
|
|
) : (
|
|
<form
|
|
onSubmit={(event) => {
|
|
event.preventDefault();
|
|
void apiPost('/auth/resend-verification', { email }).then(() => setResent(true));
|
|
}}
|
|
>
|
|
<p>{t('auth:verify.error.resendPrompt')}</p>
|
|
<label className="field">
|
|
<span className="field__label">{t('auth:forgot.email')}</span>
|
|
<input
|
|
type="email"
|
|
value={email}
|
|
onChange={(event) => setEmail(event.target.value)}
|
|
required
|
|
/>
|
|
</label>
|
|
<button type="submit" className="button">
|
|
{t('auth:verify.error.resend')}
|
|
</button>
|
|
</form>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|