Unmatch error code in signUpEmail api using username plugin #2754

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

Originally created by @pijarpahlawan on GitHub (Jan 22, 2026).

When I sign up for an email using the username plugin and the username has been taken, the error code is USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER, while in USERNAME_ERROR_CODES it says USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER, making it difficult to retrieve the error code.

I've also checked the source code and can't find where USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER is thrown.

Originally created by @pijarpahlawan on GitHub (Jan 22, 2026). When I sign up for an email using the username plugin and the username has been taken, the error code is USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER, while in [USERNAME_ERROR_CODES](https://github.com/better-auth/better-auth/blob/canary/packages/better-auth/src/plugins/username/error-codes.ts) it says USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER, making it difficult to retrieve the error code. I've also checked the source code and can't find where USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER is thrown.
GiteaMirror added the bug label 2026-03-13 10:18:06 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 22, 2026):

It seems you're encountering an issue with the error code USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER when using the username plugin. This error indicates that the username you are trying to register is already taken. The specific message being returned suggests a mismatch in the error handling within the signup process.

First, please ensure that your implementation accurately checks for this error and utilizes the correct method to trap it. It may be worthwhile to verify the following:

  1. Check your error handling logic: Make sure your logic captures and processes USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER properly.
  2. Refer to the error codes documentation: Ensure that you're referencing the correct constant from the USERNAME_ERROR_CODES.

If these steps do not resolve your issue, it might be beneficial to seek further assistance from the Better Auth team. Please tag @bekacru and @ping__ in your issue for more targeted help.

What specific part of the signup process can I help you clarify or troubleshoot further?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Jan 22, 2026): It seems you're encountering an issue with the error code `USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER` when using the username plugin. This error indicates that the username you are trying to register is already taken. The specific message being returned suggests a mismatch in the error handling within the signup process. First, please ensure that your implementation accurately checks for this error and utilizes the correct method to trap it. It may be worthwhile to verify the following: 1. **Check your error handling logic:** Make sure your logic captures and processes `USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER` properly. 2. **Refer to the error codes documentation:** Ensure that you're referencing the correct constant from the `USERNAME_ERROR_CODES`. If these steps do not resolve your issue, it might be beneficial to seek further assistance from the Better Auth team. Please tag @bekacru and @ping__ in your issue for more targeted help. What specific part of the signup process can I help you clarify or troubleshoot further? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Jan 22, 2026):

Hi @pijarpahlawan! I'm Dosu and I’m helping the better-auth team.

The error code USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER is not actually thrown in the codebase. The username plugin defines and uses USERNAME_IS_ALREADY_TAKEN as the error code for username collisions, with the message "Username is already taken. Please try another." This is what gets returned when a username is already taken during sign-up, not the _PLEASE_TRY_ANOTHER variant you referenced. The mismatch comes from either legacy naming or confusion between error codes and error messages in the code and docs. This can make it tricky to handle errors programmatically or with localization, since the code you receive may not match what you see in the error-codes.ts file or docs. To handle username collisions, check for USERNAME_IS_ALREADY_TAKEN in your client code. If you need strict code/message matching, you may want to track updates or patches that address error code consistency in the project.
See supporting code and discussion

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Jan 22, 2026): <!-- Greeting --> Hi @pijarpahlawan! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The error code USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER is not actually thrown in the codebase. The username plugin defines and uses USERNAME_IS_ALREADY_TAKEN as the error code for username collisions, with the message "Username is already taken. Please try another." This is what gets returned when a username is already taken during sign-up, not the _PLEASE_TRY_ANOTHER variant you referenced. The mismatch comes from either legacy naming or confusion between error codes and error messages in the code and docs. This can make it tricky to handle errors programmatically or with localization, since the code you receive may not match what you see in the error-codes.ts file or docs. To handle username collisions, check for USERNAME_IS_ALREADY_TAKEN in your client code. If you need strict code/message matching, you may want to track updates or patches that address error code consistency in the project. [See supporting code and discussion](https://github.com/better-auth/better-auth/blob/d1602ef0ae9822e462a5a42497072a0a1756e804/packages/better-auth/src/plugins/username/index.ts#L490-L536) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/66e824f0-9fa6-4139-b6bd-bfa1d5ecf88a?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/66e824f0-9fa6-4139-b6bd-bfa1d5ecf88a?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/66e824f0-9fa6-4139-b6bd-bfa1d5ecf88a?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/66e824f0-9fa6-4139-b6bd-bfa1d5ecf88a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/66e824f0-9fa6-4139-b6bd-bfa1d5ecf88a?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/66e824f0-9fa6-4139-b6bd-bfa1d5ecf88a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/66e824f0-9fa6-4139-b6bd-bfa1d5ecf88a?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20error%20code%20USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER%20is%20not%20actually%20thrown%20in%20the%20codebase.%20The%20username%20plugin%20defines%20and%20uses%20USERNAME_IS_ALREADY_TAKEN%20as%20the%20error%20code%20for%20username%20collisions%2C%20with%20the%20message%20%22Username%20is%20already%20taken.%20Please%20try%20another.%22%20This%20is%20what%20gets%20returned%20when%20a%20username%20is%20already%20taken%20during%20sign-up%2C%20not%20the%20_PLEASE_TRY_ANOTHER%20variant%20you%20referenced.%20The%20mismatch%20comes%20from%20either%20legacy%20naming%20or%20confusion%20between%20error%20codes%20and%20error%20messages%20in%20the%20code%20and%20docs.%20This%20can%20make%20it%20tricky%20to%20handle%20errors%20programmatically%20or%20with%20localization%2C%20since%20the%20code%20you%20receive%20may%20not%20match%20what%20you%20see%20in%20the%20error-codes.ts%20file%20or%20docs.%20To%20handle%20username%20collisions%2C%20check%20for%20USERNAME_IS_ALREADY_TAKEN%20in%20your%20client%20code.%20If%20you%20need%20strict%20code/message%20matching%2C%20you%20may%20want%20to%20track%20updates%20or%20patches%20that%20address%20error%20code%20consistency%20in%20the%20project.%20%20%0A%5BSee%20supporting%20code%20and%20discussion%5D%28https%3A//github.com/better-auth/better-auth/blob/d1602ef0ae9822e462a5a42497072a0a1756e804/packages/better-auth/src/plugins/username/index.ts%23L490-L536%29)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/7557)
Author
Owner

@pijarpahlawan commented on GitHub (Jan 22, 2026):

@dosu @Bekacru @ping__ this is my code

try {
      await auth.api.signUpEmail({
        body: {
          name: data.name,
          username: data.username,
          email: data.email,
          password: data.password,
          image: data.avatarKey,
        },
      });
    } catch (error) {
      console.error({ error });
      throw error;
    }

the error throwed like this

{
  error: [Error [APIError]: Username is already taken. Please try another.] {
    status: 'BAD_REQUEST',
    body: {
      code: 'USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER',
      message: 'Username is already taken. Please try another.'
    },
    headers: {},
    statusCode: 400
  }
}
@pijarpahlawan commented on GitHub (Jan 22, 2026): @dosu @Bekacru @ping__ this is my code ```ts try { await auth.api.signUpEmail({ body: { name: data.name, username: data.username, email: data.email, password: data.password, image: data.avatarKey, }, }); } catch (error) { console.error({ error }); throw error; } ``` the error throwed like this ```js { error: [Error [APIError]: Username is already taken. Please try another.] { status: 'BAD_REQUEST', body: { code: 'USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER', message: 'Username is already taken. Please try another.' }, headers: {}, statusCode: 400 } } ```
Author
Owner

@dosubot[bot] commented on GitHub (Jan 22, 2026):

The error code mismatch happens because the username plugin throws an APIError with only the message "Username is already taken. Please try another." and does not set the code field. The better-call library then auto-generates the code from the message, resulting in USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER in the API response—even though only USERNAME_IS_ALREADY_TAKEN is defined in the codebase. This is a known issue and has caused confusion for error handling and localization. No fix for this specific code has been merged yet, so for now, you should handle both the generated code and the defined constant in your client code if you want to be robust. For best results, always reference exported error code constants where possible, but be aware of these mismatches for now.
See discussion and code references
See plugin implementation

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Jan 22, 2026): <!-- Answer --> The error code mismatch happens because the username plugin throws an APIError with only the message "Username is already taken. Please try another." and does not set the code field. The better-call library then auto-generates the code from the message, resulting in USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER in the API response—even though only USERNAME_IS_ALREADY_TAKEN is defined in the codebase. This is a known issue and has caused confusion for error handling and localization. No fix for this specific code has been merged yet, so for now, you should handle both the generated code and the defined constant in your client code if you want to be robust. For best results, always reference exported error code constants where possible, but be aware of these mismatches for now. [See discussion and code references](https://github.com/better-auth/better-auth/issues/4386) [See plugin implementation](https://github.com/better-auth/better-auth/blob/d1602ef0ae9822e462a5a42497072a0a1756e804/packages/better-auth/src/plugins/username/index.ts#L483-L536) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/6687c115-1d20-42c3-8d1d-778c436c683e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/6687c115-1d20-42c3-8d1d-778c436c683e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/6687c115-1d20-42c3-8d1d-778c436c683e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/6687c115-1d20-42c3-8d1d-778c436c683e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/6687c115-1d20-42c3-8d1d-778c436c683e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/6687c115-1d20-42c3-8d1d-778c436c683e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/6687c115-1d20-42c3-8d1d-778c436c683e?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20error%20code%20mismatch%20happens%20because%20the%20username%20plugin%20throws%20an%20APIError%20with%20only%20the%20message%20%22Username%20is%20already%20taken.%20Please%20try%20another.%22%20and%20does%20not%20set%20the%20code%20field.%20The%20better-call%20library%20then%20auto-generates%20the%20code%20from%20the%20message%2C%20resulting%20in%20USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER%20in%20the%20API%20response%E2%80%94even%20though%20only%20USERNAME_IS_ALREADY_TAKEN%20is%20defined%20in%20the%20codebase.%20This%20is%20a%20known%20issue%20and%20has%20caused%20confusion%20for%20error%20handling%20and%20localization.%20No%20fix%20for%20this%20specific%20code%20has%20been%20merged%20yet%2C%20so%20for%20now%2C%20you%20should%20handle%20both%20the%20generated%20code%20and%20the%20defined%20constant%20in%20your%20client%20code%20if%20you%20want%20to%20be%20robust.%20For%20best%20results%2C%20always%20reference%20exported%20error%20code%20constants%20where%20possible%2C%20but%20be%20aware%20of%20these%20mismatches%20for%20now.%20%20%0A%5BSee%20discussion%20and%20code%20references%5D%28https%3A//github.com/better-auth/better-auth/issues/4386%29%20%20%0A%5BSee%20plugin%20implementation%5D%28https%3A//github.com/better-auth/better-auth/blob/d1602ef0ae9822e462a5a42497072a0a1756e804/packages/better-auth/src/plugins/username/index.ts%23L483-L536%29)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/7557)
Author
Owner

@bytaesu commented on GitHub (Jan 23, 2026):

Hi @pijarpahlawan,

We recently improved error handling.
@himself65 Is this fixed in v1.5?

@bytaesu commented on GitHub (Jan 23, 2026): Hi @pijarpahlawan, We recently improved error handling. @himself65 Is this fixed in v1.5?
Author
Owner

@bytaesu commented on GitHub (Jan 24, 2026):

The error codes were part of a recent improvement, so this issue may already be resolved.
It this issue persists on the latest version, feel free to reopen or mention me 😄

@bytaesu commented on GitHub (Jan 24, 2026): The error codes were part of a recent improvement, so this issue may already be resolved. It this issue persists on the latest version, feel free to reopen or mention me 😄
Author
Owner

@pijarpahlawan commented on GitHub (Jan 26, 2026):

Okey, thank you for solving this issue 😁

@pijarpahlawan commented on GitHub (Jan 26, 2026): Okey, thank you for solving this issue 😁
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2754