[GH-ISSUE #6579] Add hook usernameAvailabilityChecker to username plugin #10558

Open
opened 2026-04-13 06:46:55 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @typed-sigterm on GitHub (Dec 7, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6579

Is this suited for github?

  • Yes, this is suited for github

7d5f12b1f9/packages/better-auth/src/plugins/username/index.ts (L462-L466)

For some reason, I have two authenticating systems, and the usernames must be unique between the two systems. In better-auth, The logic for checking if a username is already in use is hard-coded. I can only do

throw new APIError('UNPROCESSABLE_ENTITY', {
   code: 'USERNAME_IS_ALREADY_TAKEN',
   message: USERNAME_ERROR_CODES.USERNAME_IS_ALREADY_TAKEN,
});

but this breaks /is-username-available. (not returning { available: false } but fail)

Describe the solution you'd like

Call option.usernameAvailabilityChecker before database querying. If it returns false, directly return { available: false }.

Also, /sign-in/username should be update. (there seems to be a lot of duplicate code)

Describe alternatives you've considered

N/A

Additional context

No response

Originally created by @typed-sigterm on GitHub (Dec 7, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6579 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. https://github.com/better-auth/better-auth/blob/7d5f12b1f9df2d226a836d63734814ed62d3541c/packages/better-auth/src/plugins/username/index.ts#L462-L466 For some reason, I have two authenticating systems, and the usernames must be unique between the two systems. In better-auth, The logic for checking if a username is already in use is hard-coded. I can only do ```ts throw new APIError('UNPROCESSABLE_ENTITY', { code: 'USERNAME_IS_ALREADY_TAKEN', message: USERNAME_ERROR_CODES.USERNAME_IS_ALREADY_TAKEN, }); ``` but this breaks `/is-username-available`. (not returning `{ available: false }` but fail) ### Describe the solution you'd like Call `option.usernameAvailabilityChecker` before database querying. If it returns `false`, directly return `{ available: false }`. Also, `/sign-in/username` should be update. (there seems to be a lot of duplicate code) ### Describe alternatives you've considered N/A ### Additional context _No response_
GiteaMirror added the credentials label 2026-04-13 06:46:55 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 7, 2025):

Thanks for opening this issue! We understand your need for a configurable hook to check username availability. Your suggestion to call a custom checker (usernameAvailabilityChecker) before performing the DB query – so that if it returns false, the API immediately returns { available: false } instead of throwing an error – makes sense to ensure consistency across both the /is-username-available and /sign-in/username endpoints. We’ll look into reducing duplicate code between these endpoints as part of this improvement. Could you share more details on any additional requirements or edge cases you’d like this hook to handle? tag @better-auth-agent if you would like an answer from the Agent

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

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3621639266 --> @better-auth-agent[bot] commented on GitHub (Dec 7, 2025): Thanks for opening this issue! We understand your need for a configurable hook to check username availability. Your suggestion to call a custom checker (usernameAvailabilityChecker) before performing the DB query – so that if it returns false, the API immediately returns { available: false } instead of throwing an error – makes sense to ensure consistency across both the /is-username-available and /sign-in/username endpoints. We’ll look into reducing duplicate code between these endpoints as part of this improvement. Could you share more details on any additional requirements or edge cases you’d like this hook to handle? tag @better-auth-agent if you would like an answer from the Agent _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/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Mar 8, 2026):

Hi, @typed-sigterm. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested a usernameAvailabilityChecker hook for the username plugin to allow custom uniqueness checks across multiple systems.
  • This would enhance the /is-username-available endpoint and help prevent errors.
  • You also suggested refactoring /sign-in/username to reduce duplicate code.
  • The maintainer agreed with the approach and asked for more details on additional requirements or edge cases.
  • No further updates or details have been provided since.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of better-auth by commenting here.
  • If I don’t hear back within 7 days, this issue will be automatically closed.

Thanks for your understanding and contribution!

<!-- gh-comment-id:4019376013 --> @dosubot[bot] commented on GitHub (Mar 8, 2026): Hi, @typed-sigterm. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested a `usernameAvailabilityChecker` hook for the username plugin to allow custom uniqueness checks across multiple systems. - This would enhance the `/is-username-available` endpoint and help prevent errors. - You also suggested refactoring `/sign-in/username` to reduce duplicate code. - The maintainer agreed with the approach and asked for more details on additional requirements or edge cases. - No further updates or details have been provided since. **Next Steps:** - Please let me know if this issue is still relevant to the latest version of better-auth by commenting here. - If I don’t hear back within 7 days, this issue will be automatically closed. Thanks for your understanding and contribution!
Author
Owner

@typed-sigterm commented on GitHub (Mar 9, 2026):

keep open

<!-- gh-comment-id:4022835953 --> @typed-sigterm commented on GitHub (Mar 9, 2026): keep open
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10558