[GH-ISSUE #721] Username Normalization Should Use Separate Field for Normalized Format #8394

Closed
opened 2026-04-13 03:28:01 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @LexiconAlex on GitHub (Dec 2, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/721

Describe the bug

Username normalization is currently being applied directly to the username field, which prevents users from having their preferred case formatting (upper/lowercase) in their display names. The username is being forced to lowercase during storage without maintaining the user's preferred display format.

To Reproduce

Steps to reproduce the behavior:

  1. Go to user registration/creation
  2. Enter a username with mixed case (e.g., "JohnDoe")
  3. Submit the form
  4. Check the stored username in the database
  5. The username is stored in lowercase ("johndoe") without preserving the original formatting

Expected behavior

The system should:

  1. Store the original username with user-preferred case formatting for display purposes
  2. Have a separate normalizedUsername field for case-insensitive operations (searching, uniqueness checks, etc.)
  3. Use the normalized version for backend operations while displaying the user's preferred formatting

Technical Details

Current implementation in packages/better-auth/src/plugins/username/index.ts:

value: ctx.body.username.toLowerCase(),
Originally created by @LexiconAlex on GitHub (Dec 2, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/721 ## Describe the bug Username normalization is currently being applied directly to the username field, which prevents users from having their preferred case formatting (upper/lowercase) in their display names. The username is being forced to lowercase during storage without maintaining the user's preferred display format. ## To Reproduce Steps to reproduce the behavior: 1. Go to user registration/creation 2. Enter a username with mixed case (e.g., "JohnDoe") 3. Submit the form 4. Check the stored username in the database 5. The username is stored in lowercase ("johndoe") without preserving the original formatting ## Expected behavior The system should: 1. Store the original username with user-preferred case formatting for display purposes 2. Have a separate `normalizedUsername` field for case-insensitive operations (searching, uniqueness checks, etc.) 3. Use the normalized version for backend operations while displaying the user's preferred formatting ## Technical Details Current implementation in `packages/better-auth/src/plugins/username/index.ts`: ```typescript value: ctx.body.username.toLowerCase(),
GiteaMirror added the enhancementlocked labels 2026-04-13 03:28:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8394