import { IconCircleCheck as CircleCheck, IconLock as Lock, IconMail as Mail, IconMailCheck as MailCheck } from '@/components/icons'; import { useMemo, useState, type FormEvent } from 'react'; import { Link } from 'react-router-dom'; import { StatefulButton, type ButtonState } from '@/components/ui/motion/button/stateful'; import { Input } from '@/components/ui/motion/input'; import { api, unwrap } from '../../api/client'; import { AUTH_BUTTON_PRIMARY, AUTH_LINK, AuthDone, AuthError, AuthShell, FIELD } from './AuthShell'; /** "Forgot your password?": asks Supabase to e-mail a reset link. The answer never says whether the address exists. */ export function ForgotPage() { const [email, setEmail] = useState(''); const [state, setState] = useState('idle'); const [err, setErr] = useState(null); const [sent, setSent] = useState(false); const submit = async (e: FormEvent) => { e.preventDefault(); setState('loading'); setErr(null); try { await unwrap(api.POST('/api/auth/forgot', { body: { email } })); setSent(true); } catch (x) { setErr(x); } finally { setState('idle'); } }; return (
{sent ? ( } title="Check your inbox" action={Back to sign in}> If an account exists for {email}, we sent a link to set a new password. It works once and expires after a short time. ) : (
{!!err && } } classNames={FIELD} /> Send the reset link

Back to sign in

)}
); } /** Opened from the reset e-mail: Supabase puts a short-lived token in the address (#access_token=...&type=recovery). */ export function ResetPage() { const params = useMemo(() => new URLSearchParams((typeof window !== 'undefined' ? window.location.hash : '').replace(/^#/, '')), []); const token = params.get('access_token') || ''; const linkError = params.get('error_description'); const [password, setPassword] = useState(''); const [again, setAgain] = useState(''); const [state, setState] = useState('idle'); const [err, setErr] = useState(null); const [done, setDone] = useState(false); const mismatch = again.length > 0 && again !== password; const submit = async (e: FormEvent) => { e.preventDefault(); if (mismatch || password.length < 10) return; setState('loading'); setErr(null); try { await unwrap(api.POST('/api/auth/reset', { body: { access_token: token, password } })); if (typeof window !== 'undefined') window.history.replaceState(null, '', '/reset'); // drop the token from the address bar setDone(true); } catch (x) { setErr(x); } finally { setState('idle'); } }; return (
{done ? ( } title="Password changed" action={Go to sign in}> Your new password is set. Sign in with it now. ) : !token ? ( Send a new reset link}> {linkError ? decodeURIComponent(linkError.replace(/\+/g, ' ')) : 'The reset link is incomplete or has already been used.'} Ask for a new one. ) : (
{!!err && } 0 && password.length < 10 ? 'Use at least 10 characters.' : undefined} leftIcon={} classNames={FIELD} autoFocus /> } classNames={FIELD} /> Save the new password
)}
); }