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:
2026-11-27 03:14:50 -05:00
co-authored by Claude Opus 5.5
parent 87c650aca1
commit d99498be0b
9 changed files with 50 additions and 44 deletions
+6 -10
View File
@@ -1,4 +1,6 @@
<script lang="ts">
import { PASSWORD_MIN_LENGTH, PASSWORDS_DIFFER } from '#lib/auth/password.js';
import { knownCopy } from '#lib/api/error-copy.js';
import { pageTitle } from '#lib/branding.js';
import { goto } from '$app/navigation';
import { onMount } from 'svelte';
@@ -32,20 +34,14 @@
function errorMessageFor(code: string): string {
switch (code) {
case 'username_invalid':
return 'Username must be 3–32 characters: letters, numbers, underscores, hyphens.';
case 'password_too_short':
return 'Password must be at least 8 characters.';
case 'invite_required':
return 'An invite token is needed to register. Ask an admin of this server for one.';
case 'invite_invalid':
return 'That invite token is invalid, expired, or already used.';
case 'username_taken':
return 'That username is already taken.';
case 'setup_token_invalid':
return "That setup token doesn't match. Copy it from the server log; it changes each time the server restarts.";
default:
return 'Registration failed. Please try again.';
return knownCopy(code) ?? 'Registration failed. Please try again.';
}
}
@@ -54,7 +50,7 @@
if (submitting) return;
error = null;
if (password !== confirmPassword) {
error = 'Passwords do not match.';
error = PASSWORDS_DIFFER;
return;
}
submitting = true;
@@ -128,7 +124,7 @@
type="password"
autocomplete="new-password"
required
minlength="8"
minlength={PASSWORD_MIN_LENGTH}
class="w-full rounded border border-border bg-background px-3 py-2 outline-hidden focus:border-accent"
bind:value={password}
/>
@@ -139,7 +135,7 @@
type="password"
autocomplete="new-password"
required
minlength="8"
minlength={PASSWORD_MIN_LENGTH}
class="w-full rounded border border-border bg-background px-3 py-2 outline-hidden focus:border-accent"
bind:value={confirmPassword}
/>