[GH-ISSUE #8363] different auth.api.signUpEmail behaviour after upgrading better-auth from 1.4.21 to 1.5.2 #19699

Closed
opened 2026-04-15 18:59:42 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @fabioriva on GitHub (Mar 4, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8363

email and password authentication

better-auth 1.4.21 behaviour

After having succesfully signed up a new user, if i try to sign up the same user the auth.api.signUpEmail throws an error:

[InternalAPIError: User already exists. Use another email.] {
status: 'UNPROCESSABLE_ENTITY',
body: {
code: 'USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL',
message: 'User already exists. Use another email.'
},
headers: {},
statusCode: 422
}

better-aut 1.5.2 behaviour

After having succesfully signed up a new user, if i try to sign up the same user the auth.api.signUpEmail doesn't throw an error.

I believe that the API should generate an error in case someone tries to sign up a user who is already signed.

Originally created by @fabioriva on GitHub (Mar 4, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8363 email and password authentication **better-auth 1.4.21 behaviour** After having succesfully signed up a new user, if i try to sign up the same user the auth.api.signUpEmail throws an error: [InternalAPIError: User already exists. Use another email.] { status: 'UNPROCESSABLE_ENTITY', body: { code: 'USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL', message: 'User already exists. Use another email.' }, headers: {}, statusCode: 422 } **better-aut 1.5.2 behaviour** After having succesfully signed up a new user, if i try to sign up the same user the auth.api.signUpEmail doesn't throw an error. I believe that the API should generate an error in case someone tries to sign up a user who is already signed.
GiteaMirror added the lockedbug labels 2026-04-15 18:59:42 -05:00
Author
Owner

@himself65 commented on GitHub (Mar 4, 2026):

From #8091, this is intentional — it prevents attackers from discovering which emails are registered.

<!-- gh-comment-id:3996012670 --> @himself65 commented on GitHub (Mar 4, 2026): From #8091, this is intentional — it prevents attackers from discovering which emails are registered.
Author
Owner

@himself65 commented on GitHub (Mar 4, 2026):

This is by design — commit 3ec7d41a9 (PR #8091) introduced user enumeration protection on the sign-up endpoint. When requireEmailVerification: true or autoSignIn: false, the endpoint now returns a 200 OK with a synthetic user instead of throwing a 422 error, to prevent attackers from discovering which emails are registered.

You can use the onExistingUserSignUp callback to detect duplicate sign-up attempts:

const auth = betterAuth({
  emailAndPassword: {
    enabled: true,
    requireEmailVerification: true,
    onExistingUserSignUp: async ({ user }, request) => {
      // This fires when someone tries to sign up with an existing email
      console.log(`Duplicate sign-up attempt for: ${user.email}`);
      // You could send a "someone tried to register with your email" notification
    },
  },
});

If you want the old behavior (throw on duplicate), set both autoSignIn: true and requireEmailVerification: false — but note this is a security trade-off as it lets attackers discover which emails are registered.

<!-- gh-comment-id:3996023299 --> @himself65 commented on GitHub (Mar 4, 2026): This is by design — commit 3ec7d41a9 (PR #8091) introduced user enumeration protection on the sign-up endpoint. When `requireEmailVerification: true` or `autoSignIn: false`, the endpoint now returns a 200 OK with a synthetic user instead of throwing a 422 error, to prevent attackers from discovering which emails are registered. You can use the `onExistingUserSignUp` callback to detect duplicate sign-up attempts: ```typescript const auth = betterAuth({ emailAndPassword: { enabled: true, requireEmailVerification: true, onExistingUserSignUp: async ({ user }, request) => { // This fires when someone tries to sign up with an existing email console.log(`Duplicate sign-up attempt for: ${user.email}`); // You could send a "someone tried to register with your email" notification }, }, }); ``` If you want the old behavior (throw on duplicate), set both `autoSignIn: true` and `requireEmailVerification: false` — but note this is a security trade-off as it lets attackers discover which emails are registered.
Author
Owner

@fabioriva commented on GitHub (Mar 4, 2026):

@himself65
Great, thank you for the explanation

<!-- gh-comment-id:3996033988 --> @fabioriva commented on GitHub (Mar 4, 2026): @himself65 Great, thank you for the explanation
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19699