refactor(web): one password rule and one wording for account-form errors (DRY W4)
The 8-character minimum was written into sign-up, reset, Settings › Account and Admin › Users as minlength="8" and a message, and each page mapped password_too_short, username_invalid and username_taken to its own copy of the same sentence. lib/auth/password.ts now holds the minimum, the hint and "Passwords do not match.", and the pages take an error code's wording from the shared error copy (knownCopy), falling back to their own. username_invalid's shared copy now states the rule (3–32 characters: letters, numbers, underscores, hyphens), as the pages did, on web and Android alike. Account's mismatch line reads "Passwords do not match." like the other forms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,12 @@ import errorCopyJson from '../styles/error-copy.json';
|
||||
|
||||
export const ERROR_COPY: Readonly<Record<string, string>> = errorCopyJson;
|
||||
|
||||
/** The fixed copy for a known error code, or undefined for any other code,
|
||||
so a form can fall back to its own wording. */
|
||||
export function knownCopy(code: string | null | undefined): string | undefined {
|
||||
return code && code !== 'unknown' ? ERROR_COPY[code] : undefined;
|
||||
}
|
||||
|
||||
export function copyForCode(code: string | null | undefined): string {
|
||||
if (!code) return ERROR_COPY.unknown ?? 'Something went wrong.';
|
||||
return ERROR_COPY[code] ?? ERROR_COPY.unknown ?? 'Something went wrong.';
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// The account-form rules every password field shares (sign-up, reset,
|
||||
// Settings › Account, Admin › Users). The server enforces the same minimum
|
||||
// (password_too_short); the field's minlength only saves a round trip.
|
||||
|
||||
export const PASSWORD_MIN_LENGTH = 8;
|
||||
|
||||
/** The hint under a new-password field. */
|
||||
export const PASSWORD_HINT = `At least ${PASSWORD_MIN_LENGTH} characters.`;
|
||||
|
||||
/** Said when a password and its confirmation differ. */
|
||||
export const PASSWORDS_DIFFER = 'Passwords do not match.';
|
||||
@@ -7,7 +7,7 @@
|
||||
"rate_limited": "Too many attempts. Wait a few minutes and try again.",
|
||||
"wrong_password": "Current password is incorrect.",
|
||||
"password_too_short": "Password must be at least 8 characters.",
|
||||
"username_invalid": "That username isn't valid.",
|
||||
"username_invalid": "Username must be 3–32 characters: letters, numbers, underscores, hyphens.",
|
||||
"username_taken": "That username is already taken.",
|
||||
"email_invalid": "Enter a valid email address.",
|
||||
"email_taken": "That email is already in use.",
|
||||
|
||||
Reference in New Issue
Block a user