[PR #8521] [MERGED] fix: throw on duplicate email when autoSignIn: false without requireEmailVerification #8034

Closed
opened 2026-03-13 13:57:34 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8521
Author: @himself65
Created: 3/9/2026
Status: Merged
Merged: 3/9/2026
Merged by: @himself65

Base: canaryHead: worktree-fix-signup-duplicate-email


📝 Commits (1)

  • 53f567f fix(auth): throw on duplicate email when autoSignIn: false without requireEmailVerification

📊 Changes

2 files changed (+59 additions, -7 deletions)

View changed files

📝 packages/better-auth/src/api/routes/sign-up.test.ts (+55 -5)
📝 packages/better-auth/src/api/routes/sign-up.ts (+4 -2)

📄 Description

Summary

  • When autoSignIn: false was set without requireEmailVerification, signUpEmail() returned a synthetic user object for duplicate emails instead of throwing an APIError. This made it impossible for server-side callers to detect duplicates.
  • Separated the "enumeration protection" concern (shouldReturnGenericDuplicateResponse — only when requireEmailVerification is true) from the "skip session creation" concern (shouldSkipAutoSignIn — when autoSignIn: false or requireEmailVerification).
  • New users with autoSignIn: false still correctly get token: null without a session.
Config Duplicate email New user
autoSignIn: false only Throws APIError (422) Returns token: null
requireEmailVerification: true Returns synthetic user Returns token: null
Both Returns synthetic user Returns token: null
Neither (default) Throws APIError (422) Returns session token

Test plan

  • Updated existing tests to expect error for duplicate with autoSignIn: false alone
  • Added test: new sign-up with autoSignIn: false returns token: null
  • Added test: onExistingUserSignUp not called when autoSignIn: false without requireEmailVerification
  • All 26 sign-up tests pass
  • pnpm typecheck passes
  • pnpm lint passes

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8521 **Author:** [@himself65](https://github.com/himself65) **Created:** 3/9/2026 **Status:** ✅ Merged **Merged:** 3/9/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `worktree-fix-signup-duplicate-email` --- ### 📝 Commits (1) - [`53f567f`](https://github.com/better-auth/better-auth/commit/53f567fd71b197d1964da3ad284f4682dbc2d235) fix(auth): throw on duplicate email when autoSignIn: false without requireEmailVerification ### 📊 Changes **2 files changed** (+59 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/sign-up.test.ts` (+55 -5) 📝 `packages/better-auth/src/api/routes/sign-up.ts` (+4 -2) </details> ### 📄 Description ## Summary - When `autoSignIn: false` was set **without** `requireEmailVerification`, `signUpEmail()` returned a synthetic user object for duplicate emails instead of throwing an `APIError`. This made it impossible for server-side callers to detect duplicates. - Separated the "enumeration protection" concern (`shouldReturnGenericDuplicateResponse` — only when `requireEmailVerification` is true) from the "skip session creation" concern (`shouldSkipAutoSignIn` — when `autoSignIn: false` or `requireEmailVerification`). - New users with `autoSignIn: false` still correctly get `token: null` without a session. | Config | Duplicate email | New user | |---|---|---| | `autoSignIn: false` only | Throws `APIError` (422) | Returns `token: null` | | `requireEmailVerification: true` | Returns synthetic user | Returns `token: null` | | Both | Returns synthetic user | Returns `token: null` | | Neither (default) | Throws `APIError` (422) | Returns session token | ## Test plan - [x] Updated existing tests to expect error for duplicate with `autoSignIn: false` alone - [x] Added test: new sign-up with `autoSignIn: false` returns `token: null` - [x] Added test: `onExistingUserSignUp` not called when `autoSignIn: false` without `requireEmailVerification` - [x] All 26 sign-up tests pass - [x] `pnpm typecheck` passes - [x] `pnpm lint` passes --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:57:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8034