[PR #7354] [CLOSED] fix(sign-up): ensure verification email sent only when both sendOnSignUp and sendVerificationEmail are set #32855

Closed
opened 2026-04-17 23:34:11 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7354
Author: @mrgrauel
Created: 1/14/2026
Status: Closed

Base: canaryHead: fix/send-on-sign-up-override


📝 Commits (8)

  • 7266f27 fix(sign-up): update email verification logic to ensure verification email is sent only when both conditions are met
  • 9905827 test(sign-in, sign-up): adjust verification email expectations in tests to reflect updated logic
  • 48178fe test(sign-in, sign-up): add tests for verification email logic when sendOnSignIn and sendOnSignUp are undefined
  • 35e60d1 test(sign-in): update verification email test to reflect that email will not be sent when sendOnSignIn is undefined
  • 18cbef2 test(sign-up): update verification email test to reflect that email will not be sent when sendOnSignUp is undefined and sendVerificationEmail defaults to false
  • b103883 test(sign-up): remove redundant test for verification email when only sendOnSignUp is set
  • 659d0be test(sign-up): remove additional tests for verification email when conditions are not met
  • 87a9e72 test(sign-up): enhance email verification tests to cover new scenarios and update expectations

📊 Changes

3 files changed (+242 additions, -19 deletions)

View changed files

📝 packages/better-auth/src/api/routes/sign-in.test.ts (+28 -5)
📝 packages/better-auth/src/api/routes/sign-up.test.ts (+202 -0)
📝 packages/better-auth/src/api/routes/sign-up.ts (+12 -14)

📄 Description

Description

This PR fixes the email verification logic during sign-up to ensure verification emails are only sent when both sendOnSignUp and sendVerificationEmail are configured.

Problem

Previously, the condition used an OR operator (||), which meant verification emails could be sent when either sendOnSignUp was true OR requireEmailVerification was true, even if sendVerificationEmail was not provided. This could lead to errors or unexpected behavior.

Solution

Changed the condition to use AND (&&) to require both sendOnSignUp and sendVerificationEmail to be truthy:

// Before:
if (
  ctx.context.options.emailVerification?.sendOnSignUp ||
  ctx.context.options.emailAndPassword.requireEmailVerification
) {
  // ...
}

// After:
if (
  ctx.context.options.emailVerification?.sendOnSignUp &&
  ctx.context.options.emailVerification?.sendVerificationEmail
) {
  // ...
}

Changes

  • Updated sign-up route to require both sendOnSignUp AND sendVerificationEmail before sending verification emails
  • Added comprehensive tests for email verification logic
  • Fixed unused spy in test (removed unused mock that was never wired into auth instance)

Behavior

  • Verification email is sent only when both sendOnSignUp: true AND sendVerificationEmail function is provided
  • If either is missing/undefined, no verification email is sent during sign-up
  • This ensures the email sending logic only runs when properly configured

🔄 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/7354 **Author:** [@mrgrauel](https://github.com/mrgrauel) **Created:** 1/14/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/send-on-sign-up-override` --- ### 📝 Commits (8) - [`7266f27`](https://github.com/better-auth/better-auth/commit/7266f27abdadd98701942ebc01ce5e3b74489e18) fix(sign-up): update email verification logic to ensure verification email is sent only when both conditions are met - [`9905827`](https://github.com/better-auth/better-auth/commit/990582721b00100bc6e088afe49158b357e6b01c) test(sign-in, sign-up): adjust verification email expectations in tests to reflect updated logic - [`48178fe`](https://github.com/better-auth/better-auth/commit/48178feafb52c4ab02160f95272108e313ce3af0) test(sign-in, sign-up): add tests for verification email logic when sendOnSignIn and sendOnSignUp are undefined - [`35e60d1`](https://github.com/better-auth/better-auth/commit/35e60d1649cc10377626cee6deae58ef6cc146b1) test(sign-in): update verification email test to reflect that email will not be sent when sendOnSignIn is undefined - [`18cbef2`](https://github.com/better-auth/better-auth/commit/18cbef2188a50c1ff3337b176f23633441c91b93) test(sign-up): update verification email test to reflect that email will not be sent when sendOnSignUp is undefined and sendVerificationEmail defaults to false - [`b103883`](https://github.com/better-auth/better-auth/commit/b103883a355b2ec107425a8cdbe12157a83183f6) test(sign-up): remove redundant test for verification email when only sendOnSignUp is set - [`659d0be`](https://github.com/better-auth/better-auth/commit/659d0be4c911e3c8927bab561ccf21e43211c774) test(sign-up): remove additional tests for verification email when conditions are not met - [`87a9e72`](https://github.com/better-auth/better-auth/commit/87a9e72a70dc90c79371698e5da44487d4a51e1e) test(sign-up): enhance email verification tests to cover new scenarios and update expectations ### 📊 Changes **3 files changed** (+242 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/sign-in.test.ts` (+28 -5) 📝 `packages/better-auth/src/api/routes/sign-up.test.ts` (+202 -0) 📝 `packages/better-auth/src/api/routes/sign-up.ts` (+12 -14) </details> ### 📄 Description ## Description This PR fixes the email verification logic during sign-up to ensure verification emails are only sent when both `sendOnSignUp` and `sendVerificationEmail` are configured. ## Problem Previously, the condition used an OR operator (`||`), which meant verification emails could be sent when either `sendOnSignUp` was true OR `requireEmailVerification` was true, even if `sendVerificationEmail` was not provided. This could lead to errors or unexpected behavior. ## Solution Changed the condition to use AND (`&&`) to require both `sendOnSignUp` and `sendVerificationEmail` to be truthy: ```typescript // Before: if ( ctx.context.options.emailVerification?.sendOnSignUp || ctx.context.options.emailAndPassword.requireEmailVerification ) { // ... } // After: if ( ctx.context.options.emailVerification?.sendOnSignUp && ctx.context.options.emailVerification?.sendVerificationEmail ) { // ... } ``` ## Changes - Updated sign-up route to require both `sendOnSignUp` AND `sendVerificationEmail` before sending verification emails - Added comprehensive tests for email verification logic - Fixed unused spy in test (removed unused mock that was never wired into auth instance) ## Behavior - Verification email is sent only when both `sendOnSignUp: true` AND `sendVerificationEmail` function is provided - If either is missing/undefined, no verification email is sent during sign-up - This ensures the email sending logic only runs when properly configured --- <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-04-17 23:34:11 -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#32855