Dynamically prevent sign up #2248

Closed
opened 2026-03-13 09:38:23 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @MakakWasTaken on GitHub (Nov 2, 2025).

Is this suited for github?

  • Yes, this is suited for github

No response

Describe the solution you'd like

I would like to be able to dynamically disable signUp. More precisely I would like to disable sign up if the user does not have an existing account or a pending invitation from the organization plugin.

These issues could all be fixed by a method like the signIn method in next-auth.

Describe alternatives you've considered

I have considered using a before hook with a createAuthMiddleware wrapper to achieve this functionality.
The goal is easily achievable when using email based login. However it becomes significantly more advanced when trying to prevent sign up for social providers.

Additional context

No response

Originally created by @MakakWasTaken on GitHub (Nov 2, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. _No response_ ### Describe the solution you'd like I would like to be able to dynamically disable signUp. More precisely I would like to disable sign up if the user does not have an existing account or a pending invitation from the organization plugin. These issues could all be fixed by a method like the signIn method in `next-auth`. ### Describe alternatives you've considered I have considered using a before hook with a `createAuthMiddleware` wrapper to achieve this functionality. The goal is easily achievable when using email based login. However it becomes significantly more advanced when trying to prevent sign up for social providers. ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 09:38:23 -05:00
Author
Owner

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

Based on similar feature requests in our issue tracker, the recommended next steps are as follows:

  1. Upgrade to a version that supports custom pre–sign‐up hooks. Then, configure a before–hook that checks whether the user already exists or whether there is a pending invitation (such as via the organization plugin). If neither condition holds, immediately return an error to block sign–up.

  2. For email–based sign–ups this is straightforward by checking the user’s record. For social providers, you’ll need to implement similar logic (for example using a custom authorize method) since the flow differs when no account exists. This is similar in concept to how some systems (like NextAuth) separate sign–up and sign–in flows [1][2].

  3. Test the hook thoroughly with both email and social providers to ensure that new accounts are only created when the invitation or account existence condition is met.

These steps should help you dynamically disable sign–up when the required conditions aren’t met. If you encounter issues, review your hook’s logic and ensure that your error handling is appropriate for both email and social logins.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 2, 2025): Based on similar feature requests in our issue tracker, the recommended next steps are as follows: 1. Upgrade to a version that supports custom pre–sign‐up hooks. Then, configure a before–hook that checks whether the user already exists or whether there is a pending invitation (such as via the organization plugin). If neither condition holds, immediately return an error to block sign–up. 2. For email–based sign–ups this is straightforward by checking the user’s record. For social providers, you’ll need to implement similar logic (for example using a custom authorize method) since the flow differs when no account exists. This is similar in concept to how some systems (like NextAuth) separate sign–up and sign–in flows [[1]](https://github.com/better-auth/better-auth/issues/2673)[[2]](https://github.com/better-auth/better-auth/issues/1142). 3. Test the hook thoroughly with both email and social providers to ensure that new accounts are only created when the invitation or account existence condition is met. These steps should help you dynamically disable sign–up when the required conditions aren’t met. If you encounter issues, review your hook’s logic and ensure that your error handling is appropriate for both email and social logins. <!-- 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

@Bekacru commented on GitHub (Nov 3, 2025):

You can use database hooks - on before create user

@Bekacru commented on GitHub (Nov 3, 2025): You can use database hooks - on before create user
Author
Owner

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

You can hook into the user creation flow by adding a “before create” database hook that checks whether the user already exists or has a pending invitation. In that hook, if the conditions aren’t met (for example, no account exists or no invitation is pending), simply abort the creation process with an appropriate error message. This solution works particularly well for email-based sign‐ups, although you’ll need to add extra logic for social provider flows where the sign-up process is more integrated. This approach lets you dynamically disable sign-up as desired while mimicking the flexibility of signIn in next‑auth [1].

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 3, 2025): You can hook into the user creation flow by adding a “before create” database hook that checks whether the user already exists or has a pending invitation. In that hook, if the conditions aren’t met (for example, no account exists or no invitation is pending), simply abort the creation process with an appropriate error message. This solution works particularly well for email-based sign‐ups, although you’ll need to add extra logic for social provider flows where the sign-up process is more integrated. This approach lets you dynamically disable sign-up as desired while mimicking the flexibility of signIn in next‑auth [[1]](https://github.com/better-auth/better-auth/issues/5724). <!-- 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

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

You can address this by implementing a before-hook on the user creation process. In your before hook (e.g., using a database hook), check if a user already exists or if there’s a pending invitation from your organization module, and—if neither is true—abort the sign‐up by throwing an appropriate error. This approach works well for email-based sign-ups, and you’ll likely need to expand your hook to cover the additional logic for social providers since their flow is different. Testing these conditions thoroughly in your development environment should help fine-tune the restrictions. With this method, you can dynamically prevent sign-ups as required [1].

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 3, 2025): You can address this by implementing a before-hook on the user creation process. In your before hook (e.g., using a database hook), check if a user already exists or if there’s a pending invitation from your organization module, and—if neither is true—abort the sign‐up by throwing an appropriate error. This approach works well for email-based sign-ups, and you’ll likely need to expand your hook to cover the additional logic for social providers since their flow is different. Testing these conditions thoroughly in your development environment should help fine-tune the restrictions. With this method, you can dynamically prevent sign-ups as required [[1]](https://github.com/better-auth/better-auth/issues/5724). <!-- 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)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2248