[PR #3340] [CLOSED] fix(username): ensure APIError code matches USERNAME_ERROR_CODES #30368

Closed
opened 2026-04-17 21:29:06 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3340
Author: @aleclarson
Created: 7/10/2025
Status: Closed

Base: mainHead: fix/username-taken-code


📝 Commits (1)

  • 25428b9 fix: set code on every new APIError in username plugin

📊 Changes

2 files changed (+29 additions, -11 deletions)

View changed files

📝 packages/better-auth/src/plugins/username/index.ts (+16 -0)
📝 packages/better-auth/src/plugins/username/username.test.ts (+13 -11)

📄 Description

The throw new APIError statements in the Username plugin do not specify the code option, so it's generated by better-call from the message option. To ensure that client-side error handling can function properly, the values of USERNAME_ERROR_CODES must use the same words/spelling as its keys.


🔄 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/3340 **Author:** [@aleclarson](https://github.com/aleclarson) **Created:** 7/10/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/username-taken-code` --- ### 📝 Commits (1) - [`25428b9`](https://github.com/better-auth/better-auth/commit/25428b97451ea39d43f70dd333329f2796db1513) fix: set `code` on every `new APIError` in username plugin ### 📊 Changes **2 files changed** (+29 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/username/index.ts` (+16 -0) 📝 `packages/better-auth/src/plugins/username/username.test.ts` (+13 -11) </details> ### 📄 Description The `throw new APIError` statements in the Username plugin do not specify the `code` option, so it's [generated by `better-call`](https://github.com/Bekacru/better-call/blob/b6f1948a1ab08833aef717fd0fac1c3871fda0f3/src/error.ts#L136-L144) from the `message` option. To ensure that [client-side error handling](https://www.better-auth.com/docs/concepts/client#error-codes) can function properly, the values of `USERNAME_ERROR_CODES` must use the same words/spelling as its keys. --- <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-04-17 21:29: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#30368