Remove vestigial `username` field from auth/users (collision footgun, no functional purpose)

オープン
#847 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
30/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
静か
技術スタック
typescript

調査の方向性

Start in packages/core/src/services/auth-validation.ts and packages/core/src/auth/config.ts to see how username is derived from the email at registration, then check the invitation-accept check in packages/core/src/routes/auth.ts. Phase 1 is a migration that drops the UNIQUE and NOT NULL constraints on users.username plus removing the invitation requirement; confirm with maintainers before attempting Phase 2, which is a multi-file column removal. Done means signup no longer fails on duplicate derived usernames and the invitation flow no longer requires a username.

索引モデルが issue の本文から書いたものです。

説明

area: auth bug maintenance priority: P2

Summary

users.username is vestigial under the current email-based auth. It is not a login credential, it's auto-derived from the email when not supplied, and its only enforced behavior (NOT NULL UNIQUE) is a liability that causes spurious signup failures. It should be removed in the near future.

What username does today

  • Not a login credential. Login is email-only everywhere — loginSchema is { email, password } (packages/core/src/routes/auth.ts) and Better Auth uses signInEmail. There is no path to sign in with a username.
  • Auto-derived, not chosen. On registration it is .optional() (packages/core/src/services/auth-validation.ts); when omitted it is generated from the email local-part: email.split('@')[0] (fallback user<timestamp>). The Better Auth create hook does the same (packages/core/src/auth/config.ts). In practice nobody enters it.
  • Display handle only, largely redundant with email + first_name/last_name (shown in admin-users list/profile).

Why it exists

Legacy CMS convention (username-based logins / @handles). The users.username TEXT NOT NULL UNIQUE column was kept and still populated after login moved to email.

The problem (why this matters)

  1. Collision trap. NOT NULL UNIQUE + email-derived default means [email protected] and [email protected] both derive username = "alice", so the second registration fails with "User with this email or username already exists" — for a field the user never set and cannot see. Different people, different emails, blocked signup.
  2. Inconsistency. Public registration treats username as optional/auto-derived, but the invitation-accept flow explicitly requires the user to type one (if (!token || !username …) → error, with its own uniqueness check) — packages/core/src/routes/auth.ts.

Proposed removal plan

Phase 1 (low-risk, do soon):

  • Drop the UNIQUE (and ideally NOT NULL) constraint on users.username (migration).
  • Stop requiring it in the invitation-accept flow.
  • This alone removes the signup-failure footgun.

Phase 2 (clean removal):

  • Drop the column entirely; remove it from registration, invitation, admin user UI, and the Better Auth additionalFields.
  • Touches ~35 files (templates, admin-users, invitation flow, schema) + a schema migration.

Notes

  • Pairs naturally with the broader legacy-auth cleanup (e.g. retiring the compatibility users.role column).
  • Keep username only if a public @handle profile feature is on the roadmap; otherwise it is dead weight.

Filed from analysis on branch feature/better-auth-poc.

主要言語
TypeScript
スター
1.8k
フォーク
219
平均マージ
2日 21時間
マージ済み PR(30日)
67

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

SonicJs-Org/sonicjs のほかの issue

SonicJs-Org/sonicjs の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。