Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
feat(auth): reset a forgotten password with an emailed code
spacesdrivec651efb288f0
diff --git a/backend/services/email/authEmails.ts b/backend/services/email/authEmails.tsindex 9da1527..ea21e99 100644--- a/backend/services/email/authEmails.ts+++ b/backend/services/email/authEmails.ts@@ -27,8 +27,9 @@ const CODE_EMAILS: Record<string, CodeEmailCopy> = {},recovery: {subject: 'Reset your Twiligent password',- lead: 'Enter this code to choose a new password.',- linkLabel: 'Or reset your password with this link',+ lead: 'Enter this code on the sign-in page, with the new password you want to use.',+ // the link signs the person in on Settings, where the Password section sets the new password+ linkLabel: 'Or sign in with this link and set a new password in Settings',},magiclink: {subject: 'Your Twiligent sign-in code',diff --git a/backend/tests/services/email/authEmails.test.ts b/backend/tests/services/email/authEmails.test.tsindex 3321c57..7ef9dfc 100644--- a/backend/tests/services/email/authEmails.test.ts+++ b/backend/tests/services/email/authEmails.test.ts@@ -21,6 +21,8 @@ test('a sign-up email carries the code and a link to Supabase Auth\'s verify endtest('without a redirect the link leaves redirect_to out, and without a hash there is no link', () => {const [noRedirect] = composeAuthEmails(hook({ action: 'recovery', redirectTo: '' }), SUPABASE_URL);assert.ok(noRedirect.text.includes('verify?token=hash-abc&type=recovery\n'));+ assert.equal(noRedirect.subject, 'Reset your Twiligent password');+ assert.ok(noRedirect.text.startsWith('Enter this code on the sign-in page, with the new password you want to use.'));const [reauth] = composeAuthEmails(hook({ action: 'reauthentication', tokenHash: '' }), SUPABASE_URL);assert.equal(reauth.text.includes('http'), false);assert.equal(reauth.subject, 'Your Twiligent confirmation code');diff --git a/frontend/src/context/AuthContext.tsx b/frontend/src/context/AuthContext.tsxindex 5fd3350..c98bd66 100644--- a/frontend/src/context/AuthContext.tsx+++ b/frontend/src/context/AuthContext.tsx@@ -12,6 +12,9 @@ export interface AuthContextValue {signUp: (email: string, password: string) => ReturnType<Auth['signUp']>;verifySignUpCode: (email: string, code: string) => ReturnType<Auth['verifyOtp']>;resendSignUpCode: (email: string) => ReturnType<Auth['resend']>;+ sendPasswordReset: (email: string) => ReturnType<Auth['resetPasswordForEmail']>;+ verifyPasswordResetCode: (email: string, code: string) => ReturnType<Auth['verifyOtp']>;+ updatePassword: (password: string) => ReturnType<Auth['updateUser']>;signInWithGoogle: (idToken: string, nonce: string) => ReturnType<Auth['signInWithIdToken']>;signOut: () => ReturnType<Auth['signOut']>;}@@ -42,6 +45,17 @@ export function AuthProvider({ children }: { children: ReactNode }) {const resendSignUpCode = (email: string) =>supabase.auth.resend({ type: 'signup', email });+ // the email's link signs the user in on Settings, where the Password section sets the new password+ const sendPasswordReset = (email: string) =>+ supabase.auth.resetPasswordForEmail(email, { redirectTo: `${window.location.origin}/settings` });++ // a correct code signs the user in, so the new password can be saved straight after+ const verifyPasswordResetCode = (email: string, code: string) =>+ supabase.auth.verifyOtp({ email, token: code, type: 'recovery' });++ // also gives an account that only used Google a password for the same user+ const updatePassword = (password: string) => supabase.auth.updateUser({ password });+// the raw nonce lets supabase confirm the google token came from this sign-inconst signInWithGoogle = (idToken: string, nonce: string) =>supabase.auth.signInWithIdToken({ provider: 'google', token: idToken, nonce });@@ -49,7 +63,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {const signOut = () => supabase.auth.signOut();return (- <AuthContext.Provider value={{ session, user: session?.user ?? null, signIn, signUp, verifySignUpCode, resendSignUpCode, signInWithGoogle, signOut }}>+ <AuthContext.Provider value={{ session, user: session?.user ?? null, signIn, signUp, verifySignUpCode, resendSignUpCode, sendPasswordReset, verifyPasswordResetCode, updatePassword, signInWithGoogle, signOut }}>{children}</AuthContext.Provider>);diff --git a/frontend/src/hooks/use-countdown.ts b/frontend/src/hooks/use-countdown.tsnew file mode 100644index 0000000..3a661f7--- /dev/null+++ b/frontend/src/hooks/use-countdown.ts@@ -0,0 +1,14 @@+import { useEffect, useState } from 'react';++// seconds left until something may happen again, such as sending another email code; 0 when it may happen now+export function useCountdown(): [secondsLeft: number, start: (seconds: number) => void] {+ const [secondsLeft, setSecondsLeft] = useState(0);++ useEffect(() => {+ if (secondsLeft <= 0) return;+ const timer = setTimeout(() => setSecondsLeft(seconds => seconds - 1), 1000);+ return () => clearTimeout(timer);+ }, [secondsLeft]);++ return [secondsLeft, setSecondsLeft];+}diff --git a/frontend/src/lib/authErrors.ts b/frontend/src/lib/authErrors.tsindex 5115116..8aed3df 100644--- a/frontend/src/lib/authErrors.ts+++ b/frontend/src/lib/authErrors.ts@@ -40,3 +40,13 @@ export const CODE_LENGTH = 6;export function cleanCode(value: string): string {return value.replace(/\D/g, '').slice(0, CODE_LENGTH);}++const PASSWORD_MESSAGES: Record<string, string> = {+ same_password: 'This is already your password. Choose a different one.',+ reauthentication_needed: 'For security, sign out and sign in again, then set the password.',+};++// Supabase's weak_password message lists what the password is missing, so it is shown as it is+export function passwordErrorMessage(error: AuthErrorLike): string {+ return (error.code && PASSWORD_MESSAGES[error.code]) || error.message;+}diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsxindex d4f30bc..3d7dc5b 100644--- a/frontend/src/pages/Login.tsx+++ b/frontend/src/pages/Login.tsx@@ -1,4 +1,4 @@-import { useEffect, useState } from 'react';+import { useState } from 'react';import type { FormEvent } from 'react';import { Link, useNavigate } from 'react-router-dom';import { toast } from 'sonner';@@ -10,11 +10,16 @@ import { Logo } from '@/components/brand/Logo';import GoogleSignInButton from '@/components/GoogleSignInButton';import type { GoogleButtonText } from '@/lib/googleIdentity';import { GOOGLE_CLIENT_ID } from '@/lib/googleIdentity';-import { emailErrorNotice, isExistingAccount } from '@/lib/authErrors';+import { emailErrorNotice, isExistingAccount, passwordErrorMessage } from '@/lib/authErrors';+import { PASSWORD_MIN_LENGTH, newPasswordProblem } from '@/lib/passwords';+import { FieldRow } from '@/components/DetailPanel';+import { useCountdown } from '@/hooks/use-countdown';import type { AuthErrorLike } from '@/lib/authErrors';import LoginBrandPanel from './LoginBrandPanel';import LoginForm from './LoginForm';import LoginCodeForm from './LoginCodeForm';+import LoginEmailForm from './LoginEmailForm';+import PasswordInput from './PasswordInput';import { LOGIN_COPY, PRIVACY_URL } from './loginCopy';import type { LoginMode } from './loginCopy';@@ -40,8 +45,21 @@ function GoogleOption({ text, onCredential }: GoogleOptionProps) {);}+// Supabase allows one email code a minute per address, so the resend button waits as long after each send+const RESEND_WAIT_SECONDS = 60;++const FAILURE_PREFIX: Record<LoginMode, string> = {+ login: "Couldn't sign in.",+ signup: "Couldn't create the account.",+ verify: "Couldn't confirm the email.",+ forgot: "Couldn't send the code.",+ reset: "Couldn't reset the password.",+};+export default function Login() {- const { signIn, signUp, verifySignUpCode, resendSignUpCode, signInWithGoogle } = useAuth();+ const {+ signIn, signUp, verifySignUpCode, resendSignUpCode, sendPasswordReset, verifyPasswordResetCode, updatePassword, signInWithGoogle,+ } = useAuth();const navigate = useNavigate();const [mode, setMode] = useState<LoginMode>('login');const [email, setEmail] = useState('');@@ -51,22 +69,15 @@ export default function Login() {const [showPassword, setShowPassword] = useState(false);const [loading, setLoading] = useState(false);const [resending, setResending] = useState(false);- const [resendIn, setResendIn] = useState(0);+ const [resendIn, startResendWait] = useCountdown();const [emailLimitMessage, setEmailLimitMessage] = useState<string | null>(null);const isLogin = mode === 'login';const copy = LOGIN_COPY[mode];- useEffect(() => {- if (resendIn <= 0) return;- const timer = setTimeout(() => setResendIn(seconds => seconds - 1), 1000);- return () => clearTimeout(timer);- }, [resendIn]);-- // Supabase allows one code a minute per address, so the button waits as long after each send- function openCodeStep(justSent: boolean) {+ function openCodeStep(nextMode: 'verify' | 'reset', justSent: boolean) {setCode('');- setResendIn(justSent ? 60 : 0);- setMode('verify');+ startResendWait(justSent ? RESEND_WAIT_SECONDS : 0);+ setMode(nextMode);}function showEmailError(prefix: string, err: unknown) {@@ -79,7 +90,7 @@ export default function Login() {async function submitLogin() {const { error } = await signIn(email, password);if (error?.code === 'email_not_confirmed') {- openCodeStep(false);+ openCodeStep('verify', false);toast.info('Confirm your email to sign in. Enter the code from your sign-up email, or send a new one.');return;}@@ -100,26 +111,52 @@ export default function Login() {setMode('login');return;}- openCodeStep(true);+ openCodeStep('verify', true);}- async function submitCode() {+ async function submitSignUpCode() {const { error } = await verifySignUpCode(email, code);if (error) throw error;toast.success('Email confirmed');navigate('/');}+ // Supabase answers the same whether or not the address has an account, so the message cannot say which+ async function submitForgot() {+ const { error } = await sendPasswordReset(email);+ if (error) throw error;+ setPassword('');+ openCodeStep('reset', true);+ toast.success(`If an account uses ${email}, a code is on its way.`);+ }++ async function submitReset() {+ const problem = newPasswordProblem(password, password);+ if (problem) throw new Error(problem);+ const { error } = await verifyPasswordResetCode(email, code);+ if (error) throw error;+ // the code has signed the user in, so a refused password is fixed from Settings instead of a new code+ const { error: passwordError } = await updatePassword(password);+ if (passwordError) {+ toast.error(`You are signed in, but the new password was not saved. ${passwordErrorMessage(passwordError)} Set it in Settings.`);+ navigate('/settings');+ return;+ }+ toast.success('Password saved');+ navigate('/');+ }++ const SUBMIT: Record<LoginMode, () => Promise<void>> = {+ login: submitLogin, signup: submitSignUp, verify: submitSignUpCode, forgot: submitForgot, reset: submitReset,+ };+async function handleSubmit(e: FormEvent<HTMLFormElement>) {e.preventDefault();setLoading(true);try {- if (mode === 'verify') await submitCode();- else if (isLogin) await submitLogin();- else await submitSignUp();+ await SUBMIT[mode]();} catch (err) {- const prefix = { login: "Couldn't sign in.", signup: "Couldn't create the account.", verify: "Couldn't confirm the email." }[mode];- showEmailError(prefix, err);+ showEmailError(FAILURE_PREFIX[mode], err);} finally {setLoading(false);}@@ -128,9 +165,9 @@ export default function Login() {async function handleResend() {setResending(true);try {- const { error } = await resendSignUpCode(email);+ const { error } = mode === 'reset' ? await sendPasswordReset(email) : await resendSignUpCode(email);if (error) throw error;- setResendIn(60);+ startResendWait(RESEND_WAIT_SECONDS);toast.success('New code sent');} catch (err) {showEmailError("Couldn't send a new code.", err);@@ -139,8 +176,8 @@ export default function Login() {}}- function switchMode() {- setMode(mode === 'signup' ? 'login' : 'signup');+ function switchMode(next: LoginMode) {+ setMode(next);setShowPassword(false);}@@ -183,21 +220,9 @@ export default function Login() {</Alert>)}- {GOOGLE_CLIENT_ID && (mode !== 'verify' || emailLimitMessage) && <GoogleOption text={copy.google} onCredential={handleGoogleCredential} />}+ {GOOGLE_CLIENT_ID && (mode === 'login' || mode === 'signup' || emailLimitMessage) && <GoogleOption text={copy.google} onCredential={handleGoogleCredential} />}- {mode === 'verify' ? (- <LoginCodeForm- copy={copy}- email={email}- code={code}- onCodeChange={setCode}- loading={loading}- onSubmit={handleSubmit}- resendIn={resendIn}- resending={resending}- onResend={handleResend}- />- ) : (+ {mode === 'login' || mode === 'signup' ? (<LoginFormisLogin={isLogin}copy={copy}@@ -209,14 +234,44 @@ export default function Login() {onTogglePassword={() => setShowPassword(visible => !visible)}loading={loading}onSubmit={handleSubmit}+ onForgotPassword={isLogin ? () => switchMode('forgot') : undefined}/>+ ) : mode === 'forgot' ? (+ <LoginEmailForm copy={copy} email={email} onEmailChange={setEmail} loading={loading} onSubmit={handleSubmit} />+ ) : (+ <LoginCodeForm+ copy={copy}+ email={email}+ code={code}+ onCodeChange={setCode}+ loading={loading}+ onSubmit={handleSubmit}+ resendIn={resendIn}+ resending={resending}+ onResend={handleResend}+ ready={mode === 'verify' || password.length >= PASSWORD_MIN_LENGTH}+ >+ {mode === 'reset' && (+ <FieldRow label="New password" htmlFor="password">+ <PasswordInput+ id="password"+ value={password}+ onChange={setPassword}+ placeholder={`At least ${PASSWORD_MIN_LENGTH} characters`}+ autoComplete="new-password"+ showPassword={showPassword}+ onTogglePassword={() => setShowPassword(visible => !visible)}+ />+ </FieldRow>+ )}+ </LoginCodeForm>)}<p className="text-center text-sm text-ink-muted">{copy.switchPrompt}{' '}<buttontype="button"- onClick={switchMode}+ onClick={() => switchMode(copy.switchTo)}className="rounded-sm font-medium text-brand-text underline-offset-4 hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring">{copy.switchAction}diff --git a/frontend/src/pages/LoginCodeForm.tsx b/frontend/src/pages/LoginCodeForm.tsxindex 81b4e14..a525b50 100644--- a/frontend/src/pages/LoginCodeForm.tsx+++ b/frontend/src/pages/LoginCodeForm.tsx@@ -1,4 +1,4 @@-import type { FormEvent } from 'react';+import type { FormEvent, ReactNode } from 'react';import { ArrowRight, RotateCw } from 'lucide-react';import { Button } from '@/components/ui/button';import { Input } from '@/components/ui/input';@@ -18,10 +18,14 @@ export interface LoginCodeFormProps {resendIn: number;resending: boolean;onResend: () => void;+ // more fields after the code, such as the new password on the reset step+ children?: ReactNode;+ // false while those fields are not ready; the code length is checked here+ ready?: boolean;}export default function LoginCodeForm({- copy, email, code, onCodeChange, loading, onSubmit, resendIn, resending, onResend,+ copy, email, code, onCodeChange, loading, onSubmit, resendIn, resending, onResend, children, ready = true,}: LoginCodeFormProps) {return (<form onSubmit={onSubmit} className="flex flex-col gap-4">@@ -44,7 +48,8 @@ export default function LoginCodeForm({<p id="code-help" className="text-sm text-ink-muted">Sent to <span className="font-medium text-ink">{email}</span>. If it has not arrived, check your spam folder.</p>- <Button type="submit" size="lg" className="mt-2 w-full" disabled={loading || code.length !== CODE_LENGTH}>+ {children}+ <Button type="submit" size="lg" className="mt-2 w-full" disabled={loading || !ready || code.length !== CODE_LENGTH}>{loading && <Spinner className="size-4" />}{loading ? copy.busy : copy.submit}{!loading && <ArrowRight data-icon="inline-end" />}diff --git a/frontend/src/pages/LoginEmailForm.tsx b/frontend/src/pages/LoginEmailForm.tsxnew file mode 100644index 0000000..7cb99b3--- /dev/null+++ b/frontend/src/pages/LoginEmailForm.tsx@@ -0,0 +1,40 @@+import type { FormEvent } from 'react';+import { ArrowRight } from 'lucide-react';+import { Button } from '@/components/ui/button';+import { Input } from '@/components/ui/input';+import { Spinner } from '@/components/ui/spinner';+import { FieldRow } from '@/components/DetailPanel';+import type { LoginCopy } from './loginCopy';++export interface LoginEmailFormProps {+ copy: LoginCopy;+ email: string;+ onEmailChange: (value: string) => void;+ loading: boolean;+ onSubmit: (e: FormEvent<HTMLFormElement>) => void;+}++export default function LoginEmailForm({ copy, email, onEmailChange, loading, onSubmit }: LoginEmailFormProps) {+ return (+ <form onSubmit={onSubmit} className="flex flex-col gap-4">+ <FieldRow label="Email" htmlFor="email">+ <Input+ id="email"+ type="email"+ className="h-(--control-h-lg)"+ placeholder="[email protected]"+ value={email}+ onChange={e => onEmailChange(e.target.value)}+ required+ autoComplete="email"+ autoFocus+ />+ </FieldRow>+ <Button type="submit" size="lg" className="mt-2 w-full" disabled={loading}>+ {loading && <Spinner className="size-4" />}+ {loading ? copy.busy : copy.submit}+ {!loading && <ArrowRight data-icon="inline-end" />}+ </Button>+ </form>+ );+}diff --git a/frontend/src/pages/LoginForm.tsx b/frontend/src/pages/LoginForm.tsxindex 29f407d..5224e7c 100644--- a/frontend/src/pages/LoginForm.tsx+++ b/frontend/src/pages/LoginForm.tsx@@ -1,9 +1,11 @@import type { FormEvent } from 'react';-import { ArrowRight, Eye, EyeOff } from 'lucide-react';+import { ArrowRight } from 'lucide-react';import { Button } from '@/components/ui/button';import { Input } from '@/components/ui/input';import { Spinner } from '@/components/ui/spinner';import { FieldRow } from '@/components/DetailPanel';+import { PASSWORD_MIN_LENGTH } from '@/lib/passwords';+import PasswordInput from './PasswordInput';import type { LoginCopy } from './loginCopy';export interface LoginFormProps {@@ -17,10 +19,12 @@ export interface LoginFormProps {onTogglePassword: () => void;loading: boolean;onSubmit: (e: FormEvent<HTMLFormElement>) => void;+ // shown on the sign-in form only+ onForgotPassword?: () => void;}export default function LoginForm({- isLogin, copy, email, password, onEmailChange, onPasswordChange, showPassword, onTogglePassword, loading, onSubmit,+ isLogin, copy, email, password, onEmailChange, onPasswordChange, showPassword, onTogglePassword, loading, onSubmit, onForgotPassword,}: LoginFormProps) {return (<form onSubmit={onSubmit} className="flex flex-col gap-4">@@ -37,31 +41,25 @@ export default function LoginForm({/></FieldRow><FieldRow label="Password" htmlFor="password">- <div className="relative">- <Input- id="password"- type={showPassword ? 'text' : 'password'}- className="h-(--control-h-lg) pr-11"- placeholder={isLogin ? 'Your password' : 'At least 6 characters'}- value={password}- onChange={e => onPasswordChange(e.target.value)}- required- minLength={6}- autoComplete={isLogin ? 'current-password' : 'new-password'}- />- <Button- type="button"- variant="ghost"- size="icon-sm"- className="absolute top-1/2 right-1.5 -translate-y-1/2 text-ink-faint hover:text-ink"- onClick={onTogglePassword}- aria-label={showPassword ? 'Hide password' : 'Show password'}- aria-pressed={showPassword}- >- {showPassword ? <EyeOff /> : <Eye />}- </Button>- </div>+ <PasswordInput+ id="password"+ value={password}+ onChange={onPasswordChange}+ placeholder={isLogin ? 'Your password' : `At least ${PASSWORD_MIN_LENGTH} characters`}+ autoComplete={isLogin ? 'current-password' : 'new-password'}+ showPassword={showPassword}+ onTogglePassword={onTogglePassword}+ /></FieldRow>+ {onForgotPassword && (+ <button+ type="button"+ onClick={onForgotPassword}+ className="-mt-2 self-end rounded-sm text-sm font-medium text-brand-text underline-offset-4 hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"+ >+ Forgot password?+ </button>+ )}<Button type="submit" size="lg" className="mt-2 w-full" disabled={loading}>{loading && <Spinner className="size-4" />}{loading ? copy.busy : copy.submit}diff --git a/frontend/src/pages/PasswordInput.tsx b/frontend/src/pages/PasswordInput.tsxnew file mode 100644index 0000000..f7735b8--- /dev/null+++ b/frontend/src/pages/PasswordInput.tsx@@ -0,0 +1,43 @@+import { Eye, EyeOff } from 'lucide-react';+import { Button } from '@/components/ui/button';+import { Input } from '@/components/ui/input';+import { PASSWORD_MIN_LENGTH } from '@/lib/passwords';++export interface PasswordInputProps {+ id: string;+ value: string;+ onChange: (value: string) => void;+ placeholder: string;+ autoComplete: 'current-password' | 'new-password';+ showPassword: boolean;+ onTogglePassword: () => void;+}++export default function PasswordInput({ id, value, onChange, placeholder, autoComplete, showPassword, onTogglePassword }: PasswordInputProps) {+ return (+ <div className="relative">+ <Input+ id={id}+ type={showPassword ? 'text' : 'password'}+ className="h-(--control-h-lg) pr-11"+ placeholder={placeholder}+ value={value}+ onChange={e => onChange(e.target.value)}+ required+ minLength={PASSWORD_MIN_LENGTH}+ autoComplete={autoComplete}+ />+ <Button+ type="button"+ variant="ghost"+ size="icon-sm"+ className="absolute top-1/2 right-1.5 -translate-y-1/2 text-ink-faint hover:text-ink"+ onClick={onTogglePassword}+ aria-label={showPassword ? 'Hide password' : 'Show password'}+ aria-pressed={showPassword}+ >+ {showPassword ? <EyeOff /> : <Eye />}+ </Button>+ </div>+ );+}diff --git a/frontend/src/pages/loginCopy.ts b/frontend/src/pages/loginCopy.tsindex 82abb0b..dc86c37 100644--- a/frontend/src/pages/loginCopy.ts+++ b/frontend/src/pages/loginCopy.ts@@ -2,8 +2,9 @@ import type { GoogleButtonText } from '@/lib/googleIdentity';export const PRIVACY_URL = 'https://blog.ujjwal.fyi/privacy/';-// verify is the code step after sign-up, or after signing in with an email that is not confirmed yet-export type LoginMode = 'login' | 'signup' | 'verify';+// verify is the code step after sign-up, or after signing in with an email that is not confirmed yet;+// forgot asks for the email of a forgotten password, and reset takes the emailed code and the new password+export type LoginMode = 'login' | 'signup' | 'verify' | 'forgot' | 'reset';export interface LoginCopy {title: string;@@ -12,6 +13,8 @@ export interface LoginCopy {busy: string;switchPrompt: string;switchAction: string;+ // where the link under the form goes+ switchTo: LoginMode;google: GoogleButtonText;}@@ -23,6 +26,7 @@ export const LOGIN_COPY: Record<LoginMode, LoginCopy> = {busy: 'Signing in',switchPrompt: 'New to Twiligent?',switchAction: 'Create an account',+ switchTo: 'signup',google: 'continue_with',},signup: {@@ -32,6 +36,7 @@ export const LOGIN_COPY: Record<LoginMode, LoginCopy> = {busy: 'Creating account',switchPrompt: 'Already have an account?',switchAction: 'Sign in',+ switchTo: 'login',google: 'signup_with',},verify: {@@ -41,6 +46,27 @@ export const LOGIN_COPY: Record<LoginMode, LoginCopy> = {busy: 'Confirming',switchPrompt: 'Wrong address?',switchAction: 'Start again',+ switchTo: 'signup',+ google: 'continue_with',+ },+ forgot: {+ title: 'Reset your password',+ lead: 'Enter the email you sign in with. We will email you a 6-digit code.',+ submit: 'Send code',+ busy: 'Sending',+ switchPrompt: 'Remembered it?',+ switchAction: 'Back to sign in',+ switchTo: 'login',+ google: 'continue_with',+ },+ reset: {+ title: 'Choose a new password',+ lead: 'Enter the code we emailed you and the password you want to use from now on.',+ submit: 'Save password and sign in',+ busy: 'Saving',+ switchPrompt: 'Remembered it?',+ switchAction: 'Back to sign in',+ switchTo: 'login',google: 'continue_with',},};diff --git a/frontend/tests/lib/authErrors.test.ts b/frontend/tests/lib/authErrors.test.tsindex d3651cd..f8aec5c 100644--- a/frontend/tests/lib/authErrors.test.ts+++ b/frontend/tests/lib/authErrors.test.ts@@ -1,6 +1,6 @@import { test } from 'node:test';import assert from 'node:assert/strict';-import { cleanCode, emailErrorNotice, isExistingAccount } from '../../src/lib/authErrors.ts';+import { cleanCode, emailErrorNotice, isExistingAccount, passwordErrorMessage } from '../../src/lib/authErrors.ts';const WORKER_LIMIT = 'Twiligent has sent all the verification emails it can today. Sign in with Google instead, or try again tomorrow.';@@ -50,3 +50,9 @@ test('a pasted code keeps its first six digits only', () => {assert.equal(cleanCode('12345678'), '123456');assert.equal(cleanCode('abc'), '');});++test('password errors say what to do, and Supabase\'s weak password reasons pass through', () => {+ assert.equal(passwordErrorMessage({ message: 'New password should be different', code: 'same_password' }), 'This is already your password. Choose a different one.');+ assert.equal(passwordErrorMessage({ message: 'reauth', code: 'reauthentication_needed' }), 'For security, sign out and sign in again, then set the password.');+ assert.equal(passwordErrorMessage({ message: 'Password should contain at least one digit.', code: 'weak_password' }), 'Password should contain at least one digit.');+});