[PR #5810] fix(email-verification): set emailVerified to true upon email verification #14488

Open
opened 2026-04-13 09:30:01 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5810

State: open
Merged: No


Fix: Remove redundant email verification when changing email

Problem

When a user with a verified email changes their email address, the system was sending two verification emails:

  1. First email (from changeEmail endpoint): Sent via sendChangeEmailVerification callback to the new email address to confirm the email change request
  2. Second email (from verifyEmail endpoint): After clicking the first verification link, a second verification email was automatically sent to the new email address again

This created an unnecessary extra step in the email change flow - the user had to verify their new email twice.

Solution

When a user verifies an email change request (by clicking the link sent to their new email), we now:

  • Update the email address to the new email
  • Set emailVerified: true immediately
  • Remove the redundant second verification email

Why This Makes Sense

The verification flow already ensures the user owns the new email:

  1. The user must be logged in (session required) to change their email
  2. The verification email is sent to the new email address via sendChangeEmailVerification (lines 793-801 in update-user.ts)
  3. Clicking the verification link sent to the new email confirms the user has access to that email address

Since the user has already verified their ownership of the new email by clicking the verification link sent to it, there's no need for an additional verification email. The act of verifying the change request is sufficient verification of the new email. This matches the pattern used for unverified email changes (lines 744-767 in update-user.ts), where a single verification email to the new address is sufficient.

Changes

  • Updated verifyEmail endpoint to set emailVerified: true when processing email changes (when updateTo is present in the token)
  • Removed the redundant token creation and second verification email sending logic
  • packages/better-auth/src/api/routes/email-verification.ts - Removed redundant verification email logic
  • packages/better-auth/src/api/routes/update-user.ts - Already sends the initial change email verification (lines 751-760)

Summary by cubic

Stop sending a second verification email after users confirm an email change. When the user clicks the change-email verification link, we update their email and mark it verified immediately.

  • Bug Fixes
    • Set emailVerified: true in verifyEmail when processing email changes.
    • Removed token generation and follow-up verification email to the new address.
    • Updated session cookie to reflect the new email with emailVerified: true.

Written for commit ddfe08660e. Summary will update automatically on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5810 **State:** open **Merged:** No --- # Fix: Remove redundant email verification when changing email ## Problem When a user with a verified email changes their email address, the system was sending **two verification emails**: 1. **First email** (from `changeEmail` endpoint): Sent via `sendChangeEmailVerification` callback to the **new email address** to confirm the email change request 2. **Second email** (from `verifyEmail` endpoint): After clicking the first verification link, a second verification email was automatically sent to the **new email address** again This created an unnecessary extra step in the email change flow - the user had to verify their new email twice. ## Solution When a user verifies an email change request (by clicking the link sent to their new email), we now: - ✅ Update the email address to the new email - ✅ Set `emailVerified: true` immediately - ❌ **Remove** the redundant second verification email ## Why This Makes Sense The verification flow already ensures the user owns the new email: 1. The user must be **logged in** (session required) to change their email 2. The verification email is sent to the **new email address** via `sendChangeEmailVerification` (lines 793-801 in `update-user.ts`) 3. Clicking the verification link sent to the new email confirms the user has access to that email address Since the user has already verified their ownership of the new email by clicking the verification link sent to it, there's no need for an additional verification email. The act of verifying the change request **is** sufficient verification of the new email. This matches the pattern used for unverified email changes (lines 744-767 in `update-user.ts`), where a single verification email to the new address is sufficient. ## Changes - Updated `verifyEmail` endpoint to set `emailVerified: true` when processing email changes (when `updateTo` is present in the token) - Removed the redundant token creation and second verification email sending logic ## Related Code - `packages/better-auth/src/api/routes/email-verification.ts` - Removed redundant verification email logic - `packages/better-auth/src/api/routes/update-user.ts` - Already sends the initial change email verification (lines 751-760) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Stop sending a second verification email after users confirm an email change. When the user clicks the change-email verification link, we update their email and mark it verified immediately. - **Bug Fixes** - Set emailVerified: true in verifyEmail when processing email changes. - Removed token generation and follow-up verification email to the new address. - Updated session cookie to reflect the new email with emailVerified: true. <sup>Written for commit ddfe08660efed9767700bf87df415c2da6e1a1ed. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 09:30:01 -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#14488