[PR #3912] [MERGED] fix(username): remove normalize transform for displayUsername #5081

Closed
opened 2026-03-13 12:10:06 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3912
Author: @oskar-gmerek
Created: 8/10/2025
Status: Merged
Merged: 8/10/2025
Merged by: @Bekacru

Base: canaryHead: fix/display-username-normalization


📝 Commits (6)

  • c4660eb fix(username): remove normalize transform for displayUsername
  • adea0d2 feat(username): enhance username plugin with display username normalization and validation options
  • 767aa18 docs
  • 6c8cd4a update api
  • 48e9b6b update docs
  • 5943efd update docs

📊 Changes

6 files changed (+519 additions, -58 deletions)

View changed files

📝 docs/content/docs/plugins/username.mdx (+101 -27)
📝 packages/better-auth/src/plugins/username/error-codes.ts (+1 -0)
📝 packages/better-auth/src/plugins/username/index.ts (+149 -19)
📝 packages/better-auth/src/plugins/username/schema.ts (+14 -2)
📝 packages/better-auth/src/plugins/username/username.test.ts (+244 -6)
📝 packages/better-auth/src/types/options.ts (+10 -4)

📄 Description

fix(username): remove normalize transform for displayUsername
feat(username): add displayUsernameValidator

This pull request restores the expected behavior of the username plugin.

Before:
It was not possible for displayUsername to have capital letters if the normalizing function for username changed capital letters to lowercase.

After:
displayUsername retains the format of the original input, and username is created on its normalized basis.
It is still possible to specify:

  • username alone (displayUsername is created based on username),
  • displayUsername alone (username is a normalized version of displayUsername),
  • both at the same time (displayUsername retains the input for displayUsername, and username normalizes the input for username).

Additionally, the displayUsernameValidator function has been added, which does nothing by default, but allows the user to provide their own validation logic for displayUsername, which is independent of the validation logic for username.


Summary by cubic

Removed normalization from displayUsername so it now preserves the original input, and added an optional displayUsernameValidator for custom validation.

  • New Features

    • Added displayUsernameValidator option to allow custom validation logic for displayUsername.
  • Bug Fixes

    • displayUsername is no longer normalized, so it can keep capital letters and formatting as entered.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3912 **Author:** [@oskar-gmerek](https://github.com/oskar-gmerek) **Created:** 8/10/2025 **Status:** ✅ Merged **Merged:** 8/10/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/display-username-normalization` --- ### 📝 Commits (6) - [`c4660eb`](https://github.com/better-auth/better-auth/commit/c4660eb810243796b562538e344ecca13e77dec4) fix(username): remove normalize transform for displayUsername - [`adea0d2`](https://github.com/better-auth/better-auth/commit/adea0d2d953f4247927b56679598e28680b38df7) feat(username): enhance username plugin with display username normalization and validation options - [`767aa18`](https://github.com/better-auth/better-auth/commit/767aa18d0637c85f7109302f624db549405e2097) docs - [`6c8cd4a`](https://github.com/better-auth/better-auth/commit/6c8cd4a49178ec7f24864d868a406f14bb5a3c33) update api - [`48e9b6b`](https://github.com/better-auth/better-auth/commit/48e9b6b63ed5d9f57622cf5a9c8c3a333df40898) update docs - [`5943efd`](https://github.com/better-auth/better-auth/commit/5943efd799dedb4f94648b93c1c765c543ac3149) update docs ### 📊 Changes **6 files changed** (+519 additions, -58 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/username.mdx` (+101 -27) 📝 `packages/better-auth/src/plugins/username/error-codes.ts` (+1 -0) 📝 `packages/better-auth/src/plugins/username/index.ts` (+149 -19) 📝 `packages/better-auth/src/plugins/username/schema.ts` (+14 -2) 📝 `packages/better-auth/src/plugins/username/username.test.ts` (+244 -6) 📝 `packages/better-auth/src/types/options.ts` (+10 -4) </details> ### 📄 Description fix(username): remove normalize transform for displayUsername feat(username): add displayUsernameValidator This pull request restores the expected behavior of the username plugin. Before: It was not possible for displayUsername to have capital letters if the normalizing function for username changed capital letters to lowercase. After: displayUsername retains the format of the original input, and username is created on its normalized basis. It is still possible to specify: - username alone (displayUsername is created based on username), - displayUsername alone (username is a normalized version of displayUsername), - both at the same time (displayUsername retains the input for displayUsername, and username normalizes the input for username). Additionally, the displayUsernameValidator function has been added, which does nothing by default, but allows the user to provide their own validation logic for displayUsername, which is independent of the validation logic for username. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Removed normalization from displayUsername so it now preserves the original input, and added an optional displayUsernameValidator for custom validation. - **New Features** - Added displayUsernameValidator option to allow custom validation logic for displayUsername. - **Bug Fixes** - displayUsername is no longer normalized, so it can keep capital letters and formatting as entered. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:10:06 -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#5081