Email confirmation, change email/password, show/hide passwords
CI / check (push) Canceled after 0s

- Sign-up emails a confirmation link (24h); unconfirmed accounts see a
  banner on the web with "send it again", and status in Settings.
- Change email (needs the password): the new address gets a confirmation
  link and only replaces the old one once clicked; the old address gets a
  heads-up with a reset-password link. Pending changes can be cancelled.
- Change password (needs the current one): signs out other sessions.
- Password fields have Show/Hide on web and mobile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzFywujuH9TiuXbr9vjoX8
This commit is contained in:
2026-10-06 13:05:26 -04:00
co-authored by Claude Opus 5.5
parent 45a7bd190a
commit 85e1643c29
25 changed files with 2077 additions and 19 deletions
+124
View File
@@ -40,6 +40,7 @@ function Settings() {
<div className="stack">
<h1>Settings</h1>
<ProfileForm me={me} />
<AccountSettings me={me} />
<SharingControls />
<Connections />
<FeaturedPicker />
@@ -148,6 +149,129 @@ function AvatarPicker({ me }: { me: MeDTO }) {
);
}
function AccountSettings({ me }: { me: MeDTO }) {
const { mutate } = useMe();
const [editing, setEditing] = useState<'email' | 'password' | null>(null);
const [message, setMessage] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
const [show, setShow] = useState(false);
const run = async (fn: () => Promise<unknown>, done: string) => {
setError(null);
try {
await fn();
await mutate();
setEditing(null);
setMessage(done);
} catch (err) {
setError((err as Error).message);
}
};
const field = (f: FormData, k: string) => String(f.get(k) ?? '');
return (
<section className="card form">
<h2>Account</h2>
<div>
<div className="muted">Email</div>
<div>
{me.email}{' '}
{me.emailVerified ? <span className="chip-small">Confirmed</span> : <span className="chip-small danger">Not confirmed</span>}
</div>
{me.pendingEmail && (
<p className="muted">
Changing to <strong>{me.pendingEmail}</strong>: open the link we sent there.{' '}
<button type="button" className="link-button" onClick={() => run(() => client.cancelEmailChange(), 'Email change cancelled.')}>
Cancel
</button>
</p>
)}
{!me.emailVerified && !me.pendingEmail && (
<button type="button" className="link-button" onClick={() => run(() => client.resendVerification(), `Sent a new link to ${me.email}.`)}>
Send the confirmation link again
</button>
)}
</div>
{editing === 'email' ? (
<form
className="form"
onSubmit={(e) => {
e.preventDefault();
const f = new FormData(e.currentTarget);
const email = field(f, 'email');
run(() => client.changeEmail({ email, password: field(f, 'password') }), `Check ${email} for a confirmation link.`);
}}
>
<label>
New email
<input name="email" type="email" required autoComplete="email" />
</label>
<label>
Your password
<input name="password" type={show ? 'text' : 'password'} required autoComplete="current-password" />
</label>
<ShowPassword show={show} setShow={setShow} />
<FormButtons label="Send confirmation link" onCancel={() => setEditing(null)} />
</form>
) : editing === 'password' ? (
<form
className="form"
onSubmit={(e) => {
e.preventDefault();
const f = new FormData(e.currentTarget);
run(
() => client.changePassword({ currentPassword: field(f, 'current'), newPassword: field(f, 'new') }),
'Password changed. Your other devices were signed out.',
);
}}
>
<label>
Current password
<input name="current" type={show ? 'text' : 'password'} required autoComplete="current-password" />
</label>
<label>
New password
<input name="new" type={show ? 'text' : 'password'} required minLength={8} maxLength={200} autoComplete="new-password" />
</label>
<ShowPassword show={show} setShow={setShow} />
<FormButtons label="Change password" onCancel={() => setEditing(null)} />
</form>
) : (
<div className="row">
<button type="button" className="btn" onClick={() => (setMessage(null), setEditing('email'))}>
Change email
</button>
<button type="button" className="btn" onClick={() => (setMessage(null), setEditing('password'))}>
Change password
</button>
</div>
)}
{message && <p className="muted">{message}</p>}
{error && <p className="error">{error}</p>}
</section>
);
}
function ShowPassword({ show, setShow }: { show: boolean; setShow: (v: boolean) => void }) {
return (
<label className="checkbox">
<input type="checkbox" checked={show} onChange={(e) => setShow(e.target.checked)} /> Show passwords
</label>
);
}
function FormButtons({ label, onCancel }: { label: string; onCancel: () => void }) {
return (
<div className="row">
<button className="btn btn-primary">{label}</button>
<button type="button" className="btn" onClick={onCancel}>
Cancel
</button>
</div>
);
}
function BlockedAccounts() {
const { data: blocked = [], mutate } = useSWR<UserSummaryDTO[]>('/me/blocks', fetcher);
return (