An option to bypass email validation #650

Closed
opened 2026-03-13 07:58:55 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @omarshehab221 on GitHub (Feb 10, 2025).

Is this suited for github?

  • Yes, this is suited for github

I'm using a custom domain in the emails of one of my projects, which triggers the better-auth email validation to throw an "Invalid email" error.

I tired this from the docs:

import { betterAuth } from "better-auth";
import { createAuthMiddleware, APIError } from "better-auth/api";
 
export const auth = betterAuth({
    hooks: {
        before: createAuthMiddleware(async (ctx) => {
            if (ctx.path !== "/sign-up/email") {
                return;
            }
            if (!ctx.body?.email.endsWith("@example.com")) {
                throw new APIError("BAD_REQUEST", {
                    message: "Email must end with @example.com",
                });
            }
        }),
    },
});

thinking that it would override the email validation, but turns out it, just adds another layer on top of it.

Describe the solution you'd like

An option in the config to bypass email validation or and only rely on the custom one configured in the hooks.

Describe alternatives you've considered

Currently I can't bypass it and can't find any alternatives.

Additional context

No response

Originally created by @omarshehab221 on GitHub (Feb 10, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I'm using a custom domain in the emails of one of my projects, which triggers the `better-auth` email validation to throw an "Invalid email" error. I tired this from the [docs](https://better-auth.vercel.app/docs/concepts/hooks#example-enforce-email-domain-restriction): ```javascript import { betterAuth } from "better-auth"; import { createAuthMiddleware, APIError } from "better-auth/api"; export const auth = betterAuth({ hooks: { before: createAuthMiddleware(async (ctx) => { if (ctx.path !== "/sign-up/email") { return; } if (!ctx.body?.email.endsWith("@example.com")) { throw new APIError("BAD_REQUEST", { message: "Email must end with @example.com", }); } }), }, }); ``` thinking that it would override the email validation, but turns out it, just adds another layer on top of it. ### Describe the solution you'd like An option in the config to bypass email validation or and only rely on the custom one configured in the hooks. ### Describe alternatives you've considered Currently I can't bypass it and can't find any alternatives. ### Additional context _No response_
Author
Owner

@dosubot[bot] commented on GitHub (Jun 11, 2025):

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

Issue Summary:

  • You requested a feature enhancement to bypass the default email validation in the better-auth library.
  • The current validation flags custom domain emails as invalid.
  • You attempted to use a custom validation hook, which supplements rather than replaces the existing validation.
  • You are seeking a configuration option to disable the default validation entirely.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If there is no response, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jun 11, 2025): Hi, @omarshehab221. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - You requested a feature enhancement to bypass the default email validation in the `better-auth` library. - The current validation flags custom domain emails as invalid. - You attempted to use a custom validation hook, which supplements rather than replaces the existing validation. - You are seeking a configuration option to disable the default validation entirely. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If there is no response, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@Bekacru commented on GitHub (Jun 16, 2025):

sorry for the very late response. Could you please share me what kind of email is failing the validator? If incase this isn't an issue anymore please close the issue

@Bekacru commented on GitHub (Jun 16, 2025): sorry for the very late response. Could you please share me what kind of email is failing the validator? If incase this isn't an issue anymore please close the issue
Author
Owner

@omarshehab221 commented on GitHub (Jun 16, 2025):

@Bekacru It a company email, like employee@company.com for example. I'm building a website for enterprise customers

@omarshehab221 commented on GitHub (Jun 16, 2025): @Bekacru It a company email, like `employee@company.com` for example. I'm building a website for enterprise customers
Author
Owner

@Bekacru commented on GitHub (Jun 16, 2025):

@omarshehab221 that shouldn't cause validation error, since it's a proper email address

@Bekacru commented on GitHub (Jun 16, 2025): @omarshehab221 that shouldn't cause validation error, since it's a proper email address
Author
Owner

@omarshehab221 commented on GitHub (Jun 16, 2025):

@Bekacru well, it did when I tried it 🤷🏻‍♀️. I'm not working on the project anymore but you may add a prp to the better auth config for convenience.

@omarshehab221 commented on GitHub (Jun 16, 2025): @Bekacru well, it did when I tried it 🤷🏻‍♀️. I'm not working on the project anymore but you may add a prp to the better auth config for convenience.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#650