[PR #6088] [MERGED] refactor: improved change email verification flow #14682

Closed
opened 2026-04-13 09:34:59 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6088
Author: @Bekacru
Created: 11/19/2025
Status: Merged
Merged: 11/19/2025
Merged by: @Bekacru

Base: canaryHead: refactor/change-email


📝 Commits (4)

  • b1f8162 refactor: improved change email verification flow
  • b698c8d add docs
  • 065009d Merge branch 'canary' into refactor/change-email
  • 1fd3de6 update test

📊 Changes

8 files changed (+252 additions, -59 deletions)

View changed files

📝 docs/content/docs/concepts/users-accounts.mdx (+31 -12)
📝 docs/content/docs/reference/options.mdx (+4 -3)
📝 packages/better-auth/src/api/routes/email-verification.test.ts (+27 -4)
📝 packages/better-auth/src/api/routes/email-verification.ts (+64 -0)
📝 packages/better-auth/src/api/routes/update-user.test.ts (+52 -34)
📝 packages/better-auth/src/api/routes/update-user.ts (+52 -6)
📝 packages/better-auth/src/plugins/phone-number/phone-number.test.ts (+2 -0)
📝 packages/core/src/types/init-options.ts (+20 -0)

📄 Description

Summary by cubic

Refactored the change email flow to optionally require confirmation from the old email, then verification on the new email before updating the account and session. By default, verification is sent to the new email; enabling confirmation adds a second step and ensures the session reflects the final, verified email.

  • Refactors

    • Email verification tokens include requestType; verifyEmail handles change-email-confirmation and change-email-verification.
    • changeEmail sends confirmation to the old email when configured, otherwise verifies the new email; updates email and emailVerified only after verification and refreshes the session cookie.
    • Added updateEmailWithoutVerification option for unverified users (optional direct update).
  • Migration

    • Use user.changeEmail.sendChangeEmailConfirmation (sendChangeEmailVerification is deprecated).
    • Configure emailVerification.sendVerificationEmail to send the verification to the new email.
    • Optionally enable user.changeEmail.updateEmailWithoutVerification for unverified users.

Written for commit 1fd3de61ec. Summary will update automatically on new commits.


🔄 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/6088 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 11/19/2025 **Status:** ✅ Merged **Merged:** 11/19/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `refactor/change-email` --- ### 📝 Commits (4) - [`b1f8162`](https://github.com/better-auth/better-auth/commit/b1f81626e13069ad05fb06bcc5279ed976695c9d) refactor: improved change email verification flow - [`b698c8d`](https://github.com/better-auth/better-auth/commit/b698c8d0505dafc41446dfa5ffe811c8446bee2b) add docs - [`065009d`](https://github.com/better-auth/better-auth/commit/065009d93ab39f08cfd9097f772145ac86a0ca80) Merge branch 'canary' into refactor/change-email - [`1fd3de6`](https://github.com/better-auth/better-auth/commit/1fd3de61ec1212c9ef574eb2552f8fbb9d9c48bd) update test ### 📊 Changes **8 files changed** (+252 additions, -59 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/concepts/users-accounts.mdx` (+31 -12) 📝 `docs/content/docs/reference/options.mdx` (+4 -3) 📝 `packages/better-auth/src/api/routes/email-verification.test.ts` (+27 -4) 📝 `packages/better-auth/src/api/routes/email-verification.ts` (+64 -0) 📝 `packages/better-auth/src/api/routes/update-user.test.ts` (+52 -34) 📝 `packages/better-auth/src/api/routes/update-user.ts` (+52 -6) 📝 `packages/better-auth/src/plugins/phone-number/phone-number.test.ts` (+2 -0) 📝 `packages/core/src/types/init-options.ts` (+20 -0) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Refactored the change email flow to optionally require confirmation from the old email, then verification on the new email before updating the account and session. By default, verification is sent to the new email; enabling confirmation adds a second step and ensures the session reflects the final, verified email. - **Refactors** - Email verification tokens include requestType; verifyEmail handles change-email-confirmation and change-email-verification. - changeEmail sends confirmation to the old email when configured, otherwise verifies the new email; updates email and emailVerified only after verification and refreshes the session cookie. - Added updateEmailWithoutVerification option for unverified users (optional direct update). - **Migration** - Use user.changeEmail.sendChangeEmailConfirmation (sendChangeEmailVerification is deprecated). - Configure emailVerification.sendVerificationEmail to send the verification to the new email. - Optionally enable user.changeEmail.updateEmailWithoutVerification for unverified users. <sup>Written for commit 1fd3de61ec1212c9ef574eb2552f8fbb9d9c48bd. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <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-13 09:34:59 -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#14682