[PR #5980] [CLOSED] fix(email-verification): make session optional for change email flow #23260

Closed
opened 2026-04-15 21:34:50 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5980
Author: @tomdenboon
Created: 11/14/2025
Status: Closed

Base: canaryHead: fix/optional-session-email-change


📝 Commits (1)

  • 7e815c5 fix(email-verification): make session optional for change email flow

📊 Changes

1 file changed (+11 additions, -22 deletions)

View changed files

📝 packages/better-auth/src/api/routes/email-verification.ts (+11 -22)

📄 Description

Description

This PR fixes the change email flow to support mobile-first applications (like Expo apps) that manage sessions client-side rather than server-side.

Previously, the email change verification flow required an active session in the request context, which broke mobile apps that store sessions in local storage and don't send session cookies to the server.

Changes

  • Removed the strict session requirement from the email change verification flow
  • Made session cookie updates conditional - only updates if a session exists and belongs to the user
  • Email updates now succeed regardless of session status

Security Considerations

Security is maintained through multiple layers:

  1. Initial /change-email request still requires authentication (uses sensitiveSessionMiddleware)
  2. Users must verify the change with their current email address
  3. Verification token is short-lived (1 hour by default)
  4. Session cookies only updated when session exists and belongs to the user (prevents session hijacking)

Testing

  • Existing tests remain compatible (they provide sessions and still work correctly)
  • Mobile apps without server-side sessions can now complete the flow

Fixes #5978


Summary by cubic

Allows email change verification to succeed without a server-side session, unblocking mobile-first apps that store sessions client-side (e.g., Expo). Fixes #5978.

  • Bug Fixes
    • Removed the strict session check when verifying and applying a new email.
    • Only update the session cookie if a matching session exists; otherwise skip without failing.

Written for commit 7e815c5dc1. 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/5980 **Author:** [@tomdenboon](https://github.com/tomdenboon) **Created:** 11/14/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/optional-session-email-change` --- ### 📝 Commits (1) - [`7e815c5`](https://github.com/better-auth/better-auth/commit/7e815c5dc1e4350c9cca76e8be820d207128485e) fix(email-verification): make session optional for change email flow ### 📊 Changes **1 file changed** (+11 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/email-verification.ts` (+11 -22) </details> ### 📄 Description ## Description This PR fixes the change email flow to support mobile-first applications (like Expo apps) that manage sessions client-side rather than server-side. Previously, the email change verification flow required an active session in the request context, which broke mobile apps that store sessions in local storage and don't send session cookies to the server. ## Changes - Removed the strict session requirement from the email change verification flow - Made session cookie updates conditional - only updates if a session exists and belongs to the user - Email updates now succeed regardless of session status ## Security Considerations Security is maintained through multiple layers: 1. ✅ Initial `/change-email` request still requires authentication (uses `sensitiveSessionMiddleware`) 2. ✅ Users must verify the change with their current email address 3. ✅ Verification token is short-lived (1 hour by default) 4. ✅ Session cookies only updated when session exists and belongs to the user (prevents session hijacking) ## Testing - Existing tests remain compatible (they provide sessions and still work correctly) - Mobile apps without server-side sessions can now complete the flow Fixes #5978 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Allows email change verification to succeed without a server-side session, unblocking mobile-first apps that store sessions client-side (e.g., Expo). Fixes #5978. - **Bug Fixes** - Removed the strict session check when verifying and applying a new email. - Only update the session cookie if a matching session exists; otherwise skip without failing. <sup>Written for commit 7e815c5dc1e4350c9cca76e8be820d207128485e. 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-15 21:34:50 -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#23260