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

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

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

State: closed
Merged: No


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5980 **State:** closed **Merged:** No --- ## 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. -->
GiteaMirror added the pull-request label 2026-04-13 09:32:26 -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#14606