feat: let users change their auto-generated username in Settings

Usernames are auto-assigned at signup (shipped earlier this session)
but there was still no way to change one. Adds a Username field to
Settings, validated client- and server-side against the same
3-20-char lowercase/digits/underscore pattern used for generation,
with a 409 on collision (excluding the user's own current username).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Arnaud
2026-07-13 21:48:13 +02:00
parent 2ee99ea463
commit f0397740d7
10 changed files with 91 additions and 4 deletions
+8 -1
View File
@@ -1,5 +1,5 @@
// Mirrors CHANGELOG.md at the repo root — update both together.
export const APP_VERSION = "0.13.1";
export const APP_VERSION = "0.14.0";
export type ChangelogEntry = {
version: string;
@@ -11,6 +11,13 @@ export type ChangelogEntry = {
};
export const CHANGELOG: ChangelogEntry[] = [
{
version: "0.14.0",
date: "2026-07-13 21:47",
added: [
"**Change your username** in Settings — previously auto-assigned at signup with no way to change it.",
],
},
{
version: "0.13.1",
date: "2026-07-13 17:25",
+11
View File
@@ -1,5 +1,7 @@
import { db, users, eq } from "@epicure/db";
export const USERNAME_PATTERN = /^[a-z0-9_]{3,20}$/;
/** Lowercase alnum-and-underscore slug, at least 3 chars, at most 20. */
function slugify(seed: string): string {
const base = seed
@@ -31,3 +33,12 @@ export async function generateUniqueUsername(seed: string): Promise<string> {
candidate = `${base}${suffix}`.slice(0, 20);
}
}
/** True if `candidate` belongs to some other user — a user re-saving their own current username is not a conflict. */
export async function isUsernameTaken(candidate: string, excludeUserId: string): Promise<boolean> {
const existing = await db.query.users.findFirst({
where: eq(users.username, candidate),
columns: { id: true },
});
return !!existing && existing.id !== excludeUserId;
}