I want to be able to change my display name

merged…
osebo55d ago

See title for context

3 repliesoldestnewest
Osebotfable-5-155d ago

Today every human is shown by their GitHub handle (users.login) — in post headers, the thread list, member lists and the header menu — and there's no way to change it. users.name exists (GitHub's full name from the OAuth profile) but is never displayed.

Plan:

  1. Schema: add a nullable users.display_name column (migration drizzle/0003_display_name.sql). Keeping it separate from name/login means nobody's shown name changes until they set one; fallback stays the GitHub handle.
  2. One helper displayName(user) → display_name ?? login ?? name, used everywhere a human name renders: components/post.tsx, thread-list.tsx, workspace member lists, user-menu.tsx, avatar initials.
  3. Settings page /settings with a small form (display name + "signed in as @login"), saved via PATCH /api/me (zod-validated, trimmed, ≤40 chars, empty resets to the handle). Linked from the header name and the nav.
  4. Agent prompts keep using the GitHub login in author="…" (stable identifier that matches commits/PRs); only the UI changes.
Osebotfable-5-155d ago

Implemented and typechecked (npm run typecheck clean), committed as ab67479 on thread/23be601f:

  • db/schema.ts + drizzle/0003_display_name.sql: nullable users.display_name. Hand-written SQL + journal entry, same as 0001/0002 (there are no snapshots past 0000).
  • lib/names.ts: displayName(u) = display_name → login → name; normalizeDisplayName() trims/collapses whitespace, empty → null, max 40 chars.
  • lib/session.ts: CurrentUser.name is now the resolved display name; new displayName field carries the raw value for the form. login unchanged.
  • app/settings/page.tsx + components/display-name-form.tsx + app/api/me/route.ts (GET/PATCH).
  • Render sites switched to the helper: components/post.tsx, thread-list.tsx, app/workspaces/page.tsx, app/workspaces/[id]/page.tsx (member list shows "Display Name · login" when they differ), components/user-menu.tsx (avatar+name now link to /settings), site-nav.tsx gains a "Settings" link.

Deploy note: run npm run db:migrate — the app will 500 on currentUser() until the column exists.

Taking a quick screenshot of the settings page via a static mockup next, then pushing.

Osebotfable-5-155d agothreadide@ab67479

Done — pushed ab67479 on thread/23be601f (open a PR from https://github.com/osebo/threadide/pull/new/thread/23be601f). Screenshot attached is a static mockup of the real markup + globals.css, since the app needs Postgres/OAuth to run.

What you get

  • /settings page (reachable from the new "Settings" nav link, or by tapping your avatar/name in the header). One field: display name. Save it and every place you appear — post headers, thread list author line, workspace member lists, the header — shows it. Clear it and you're back to your GitHub handle.
  • Member list on a workspace page shows Display Name · login when they differ, so people can still tell who's who.

How it works

  • users.display_name (nullable) — run npm run db:migrate on deploy (drizzle/0003_display_name.sql); currentUser() selects the column, so the app will error until the migration runs.
  • lib/names.ts → displayName(u) resolves display_name → login → name. All human-name rendering goes through it; login is no longer rendered directly anywhere.
  • PATCH /api/me { displayName } — zod + normalizeDisplayName (trim, collapse whitespace, ≤40 chars, empty → null). 400 with a readable message on over-long input, which the form shows inline.
  • CurrentUser.name is now the resolved display name; CurrentUser.login is still the handle; new CurrentUser.displayName is the raw stored value (used to prefill the form).

Deliberately unchanged

  • Agent prompts and posts.author_name still use the GitHub login. Claude will keep addressing you by handle in thread XML (author="osebo"), and anything tied to commits/PRs stays stable if you rename yourself. If you'd rather Claude see display names too, that's a one-line change in lib/context.ts (p.authorName → displayName(p.authorUser)) plus loading authorUser in the context query — say so and I'll do it.
  • No uniqueness check on display names. Small team, and the member list still shows the handle alongside; worth revisiting if the site opens up.

Typecheck (npm run typecheck) is clean.

/settings page at 900px (static mockup of the real markup + globals.css): header name links to settings, display name form
/settings page at 900px (static mockup of the real markup + globals.css): header name links to settings, display name form
Diff · 16 files
diff --git a/lib/names.ts b/lib/names.ts
new file mode 100644
--- /dev/null
+++ threadide/lib/names.ts
@@ -0,0 +1,21 @@
+/**
+ * How a human is shown in the UI. Users can pick a display name on /settings; until they do
+ * (or if they clear it) we show the GitHub handle, then the OAuth profile name as a last resort.
+ * Pure function so client components can use it too. Prompts deliberately don't: they keep
+ * the login via posts.author_name, which stays stable when someone renames themselves.
+ */
+export type Nameable = { displayName?: string | null; login?: string | null; name?: string | null };
+
+export const DISPLAY_NAME_MAX = 40;
+
+export function displayName(u: Nameable | null | undefined, fallback = "someone"): string {
+  return u?.displayName?.trim() || u?.login || u?.name || fallback;
+}
+
+/** Trim + collapse whitespace; empty means "use the handle again". Throws on over-long input. */
+export function normalizeDisplayName(raw: string): string | null {
+  const v = raw.replace(/\s+/g, " ").trim();
+  if (!v) return null;
+  if (v.length > DISPLAY_NAME_MAX) throw new Error(`display name must be ${DISPLAY_NAME_MAX} characters or fewer`);
+  return v;
+}
diff --git a/db/schema.ts b/db/schema.ts
--- threadide/db/schema.ts
+++ threadide/db/schema.ts
@@ -55,6 +55,9 @@ export const users = pgTable("users", {
   image: text("image"),
   // GitHub login, e.g. "osebo". Set on sign-in from the profile.
   login: text("login"),
+  // What the user chose to be shown as in the UI (settings page). Null = fall back to the login.
+  // Prompts and post.author_name keep using the login, which stays stable across renames.
+  displayName: text("display_name"),
   createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
 });
diff --git a/drizzle/0003_display_name.sql b/drizzle/0003_display_name.sql
new file mode 100644
--- /dev/null
+++ threadide/drizzle/0003_display_name.sql
@@ -0,0 +1 @@
+ALTER TABLE "users" ADD COLUMN "display_name" text;
diff --git a/lib/session.ts b/lib/session.ts
--- threadide/lib/session.ts
+++ threadide/lib/session.ts
@@ -5,10 +5,12 @@ import { and, eq } from "drizzle-orm";
 import { redirect } from "next/navigation";
 import { auth } from "@/auth";
 import { db, schema } from "@/db";
+import { displayName } from "./names";
 
 const { users, workspaceMembers, threads } = schema;
 
-export type CurrentUser = { id: string; name: string; login: string; image: string | null };
+/** `name` is what to show (display name → login → profile name); `login` is the GitHub handle. */
+export type CurrentUser = { id: string; name: string; login: string; displayName: string | null; image: string | null };
 
 export async function currentUser(): Promise<CurrentUser | null> {
@@ -16,7 +18,7 @@ export async function currentUser(): Promise<CurrentUser | null> {
   if (!id) return null;
   const [u] = await db.select().from(users).where(eq(users.id, id));
   if (!u) return null;
-  return { id: u.id, name: u.name ?? u.login ?? "someone", login: u.login ?? u.name ?? "someone", image: u.image ?? null };
+  return { id: u.id, name: displayName(u), login: u.login ?? u.name ?? "someone", displayName: u.displayName ?? null, image: u.image ?? null };
 }
diff --git a/app/api/me/route.ts b/app/api/me/route.ts
new file mode 100644
--- /dev/null
+++ threadide/app/api/me/route.ts
@@ -0,0 +1,27 @@
+import { NextResponse } from "next/server";
+import { z } from "zod";
+import { setDisplayName } from "@/lib/data";
+import { DISPLAY_NAME_MAX, normalizeDisplayName } from "@/lib/names";
+import { guarded, requireUserApi } from "@/lib/session";
+
+export const GET = guarded(async () => {
+  const user = await requireUserApi();
+  return NextResponse.json(user);
+});
+
+// Only the display name is editable for now; login/image/email come from GitHub.
+const Body = z.object({ displayName: z.string().max(DISPLAY_NAME_MAX * 4) });
+
+export const PATCH = guarded(async (req: Request) => {
+  const user = await requireUserApi();
+  const parsed = Body.safeParse(await req.json());
+  if (!parsed.success) return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
+  let name: string | null;
+  try {
+    name = normalizeDisplayName(parsed.data.displayName);
+  } catch (e) {
+    return NextResponse.json({ error: (e as Error).message }, { status: 400 });
+  }
+  await setDisplayName(user.id, name);
+  return NextResponse.json({ ok: true, displayName: name });
+});
diff --git a/components/post.tsx b/components/post.tsx
--- threadide/components/post.tsx
+++ threadide/components/post.tsx
@@ -30,9 +31,9 @@
           {post.author === "agent" ? (
             <span className="avatar avatar-fallback claude-avatar" style={{ width: 22, height: 22, fontSize: 11 }}>C</span>
           ) : (
-            <Avatar src={post.authorUser?.image} name={post.authorUser?.login ?? post.authorName} />
+            <Avatar src={post.authorUser?.image} name={displayName(post.authorUser, post.authorName)} />
           )}
-          <b>{post.author === "agent" ? "Claude" : (post.authorUser?.login ?? post.authorName)}</b>
+          <b>{post.author === "agent" ? "Claude" : displayName(post.authorUser, post.authorName)}</b>
diff --git a/components/user-menu.tsx b/components/user-menu.tsx
--- threadide/components/user-menu.tsx
+++ threadide/components/user-menu.tsx
@@ -5,8 +6,11 @@ export function UserMenu({ user }: { user: CurrentUser | null }) {
   if (!user) return null;
   return (
     <span className="user-menu">
-      {user.image && <img src={user.image} alt="" width={22} height={22} />}
-      <span className="user-login">{user.login}</span>
+      {/* Avatar + name open settings; on phones only the avatar is visible, so it must stay tappable. */}
+      <Link href="/settings" className="user-self" title="Settings">
+        {user.image && <img src={user.image} alt="" width={22} height={22} />}
+        <span className="user-login">{user.name}</span>
+      </Link>
diff --git a/app/workspaces/[id]/page.tsx b/app/workspaces/[id]/page.tsx
--- threadide/app/workspaces/[id]/page.tsx
+++ threadide/app/workspaces/[id]/page.tsx
@@ -41,8 +42,11 @@
           <div key={m.userId} className="member-row">
-            <Avatar src={m.user.image} name={m.user.login ?? "?"} />
-            <span>{m.user.login ?? m.user.name}</span>
+            <Avatar src={m.user.image} name={displayName(m.user, "?")} />
+            <span>
+              {displayName(m.user)}
+              {m.user.displayName && m.user.login && <span className="muted"> · {m.user.login}</span>}
+            </span>