[PR #7252] [CLOSED] fix: require session for change-email-verification #32776

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7252
Author: @bytaesu
Created: 1/10/2026
Status: Closed

Base: canaryHead: 2026-01-11/fix/change-email-session-verification


📝 Commits (2)

  • 10d1ce6 chore: add UNAUTHORIZED error code
  • 2c21d73 fix: require session for change-email-verification

📊 Changes

3 files changed (+250 additions, -137 deletions)

View changed files

📝 packages/better-auth/src/api/routes/email-verification.test.ts (+66 -0)
📝 packages/better-auth/src/api/routes/email-verification.ts (+183 -137)
📝 packages/core/src/error/codes.ts (+1 -0)

📄 Description

Note

To avoid confusion between flows, I replaced the if with a switch, allowing each case to be clearly separated, even if it introduces some code duplication.

Closes https://github.com/better-auth/better-auth/issues/7196


Summary by cubic

Require an active session to complete change-email verification to prevent third‑party verification attempts. Also adds an UNAUTHORIZED error and refactors the handler for clarity.

  • Bug Fixes

    • Enforce session for requestType: change-email-verification; return UNAUTHORIZED when missing.
    • Added BASE_ERROR_CODES.UNAUTHORIZED ("Authentication required") and hooked into redirectOnError.
    • Test covers verification failure without a session.
  • Refactors

    • Replaced nested conditionals with a switch on requestType, separating change-email-confirmation, change-email-verification, and legacy flow.

Written for commit 2c21d73a72. Summary will update 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/7252 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 1/10/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `2026-01-11/fix/change-email-session-verification` --- ### 📝 Commits (2) - [`10d1ce6`](https://github.com/better-auth/better-auth/commit/10d1ce60bdb6ba4119ec4bb54724b8939637f655) chore: add UNAUTHORIZED error code - [`2c21d73`](https://github.com/better-auth/better-auth/commit/2c21d73a7232bac8c496ae983ad4c4fe4c955a22) fix: require session for change-email-verification ### 📊 Changes **3 files changed** (+250 additions, -137 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/email-verification.test.ts` (+66 -0) 📝 `packages/better-auth/src/api/routes/email-verification.ts` (+183 -137) 📝 `packages/core/src/error/codes.ts` (+1 -0) </details> ### 📄 Description > [!NOTE] > To avoid confusion between flows, I replaced the `if` with a `switch`, allowing each case to be clearly separated, even if it introduces some code duplication. Closes https://github.com/better-auth/better-auth/issues/7196 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Require an active session to complete change-email verification to prevent third‑party verification attempts. Also adds an UNAUTHORIZED error and refactors the handler for clarity. - **Bug Fixes** - Enforce session for requestType: change-email-verification; return UNAUTHORIZED when missing. - Added BASE_ERROR_CODES.UNAUTHORIZED ("Authentication required") and hooked into redirectOnError. - Test covers verification failure without a session. - **Refactors** - Replaced nested conditionals with a switch on requestType, separating change-email-confirmation, change-email-verification, and legacy flow. <sup>Written for commit 2c21d73a7232bac8c496ae983ad4c4fe4c955a22. Summary will update 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-17 23:30:52 -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#32776