// "Forgot password": ask for a code (it is sent to the account's notification topic), then choose a new // password with it. Shown on the sign-in page in place of the sign-in form. import { useState } from 'react'; import { requestPasswordReset, resetPassword } from '../syncService.js'; const input = 'mt-1 block w-full rounded-xl border border-[var(--r-line)] bg-[var(--r-bg)] px-3 py-2.5 text-sm text-[var(--r-text)]'; const primary = 'w-full rounded-full bg-[var(--r-accent)] px-4 py-2.5 text-sm font-medium text-[var(--r-on)] transition hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50'; export default function ResetPasswordForm({ initialEmail = '', onDone, onBack }) { const [step, setStep] = useState('ask'); // 'ask' | 'code' | 'done' const [email, setEmail] = useState(initialEmail); const [form, setForm] = useState({ code: '', password: '', token: '' }); const [message, setMessage] = useState(''); const [error, setError] = useState(''); const [busy, setBusy] = useState(false); const ask = async (e) => { e.preventDefault(); setError(''); setBusy(true); const result = await requestPasswordReset(email.trim()); setBusy(false); if (!result.ok) { setError(result.error ?? 'Something went wrong.'); return; } setMessage(result.data?.message ?? 'If that account has a notification topic, a code was sent.'); setStep('code'); }; const reset = async (e) => { e.preventDefault(); setError(''); setBusy(true); const result = await resetPassword({ email: email.trim(), code: form.code, newPassword: form.password, token: form.token.trim() || undefined }); setBusy(false); if (!result.ok) { setError(result.error ?? 'Something went wrong.'); return; } setStep('done'); }; if (step === 'done') { return (

Password changed

You’ve been signed out everywhere. Sign in with your new password.

); } return (

Reset your password

{step === 'ask' ? (

We’ll send a one-time code to the notification topic you set up for reading reminders (ntfy).

{error &&

{error}

}
) : (
{message &&

{message}

} {error &&

{error}

}
)}
); }