import { useState, type FormEvent } from 'react'; import { apiClient } from '../api/client'; import { useAuth } from '../auth/useAuth'; import { extractErrorMessage } from '../lib/format'; import { ErrorBanner } from '../components/Spinner'; export function AccountPage() { const { user } = useAuth(); const [currentPassword, setCurrentPassword] = useState(''); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [error, setError] = useState(null); const [saved, setSaved] = useState(false); const [submitting, setSubmitting] = useState(false); async function handleSubmit(e: FormEvent) { e.preventDefault(); setError(null); setSaved(false); if (newPassword !== confirmPassword) { setError('The two new passwords do not match.'); return; } setSubmitting(true); try { await apiClient.post('/auth/password', { currentPassword, newPassword }); setCurrentPassword(''); setNewPassword(''); setConfirmPassword(''); setSaved(true); } catch (err) { setError(extractErrorMessage(err)); } finally { setSubmitting(false); } } return (

Your Account

{user?.displayName} · {user?.email}

Change Password
setCurrentPassword(e.target.value)} />
setNewPassword(e.target.value)} />
setConfirmPassword(e.target.value)} />
{error && } {saved &&

Password changed. Use the new one next time you log in.

}
); }