Skip to content

Conversation

nandan-bhat
Copy link
Contributor

@nandan-bhat nandan-bhat commented May 22, 2025

When migrating from nextjs-auth0 v3 to v4, developers may want to preserve the legacy session cookie name (appSession). However, in stateful mode, the SDK deletes the legacy cookie unconditionally after setting the new session cookie which leads to the newly set cookie being immediately removed if the names match.

This behavior breaks login flows and causes unexpected session loss.

🛠️ Changes

This PR adds a conditional guard in StatefulSessionStore.set() to ensure that:

if (
    this.sessionCookieName !== LEGACY_COOKIE_NAME &&
    reqCookies.has(LEGACY_COOKIE_NAME)
) {
    resCookies.delete(LEGACY_COOKIE_NAME);
}

This prevents accidental deletion when session.name is set to appSession a common case during v3 to v4 upgrades.

Reported Issue: #2111

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.48%. Comparing base (7bd8398) to head (298a7fc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2114      +/-   ##
==========================================
+ Coverage   82.46%   82.48%   +0.02%     
==========================================
  Files          21       21              
  Lines        2024     2027       +3     
  Branches      355      356       +1     
==========================================
+ Hits         1669     1672       +3     
  Misses        348      348              
  Partials        7        7              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nandan-bhat nandan-bhat marked this pull request as ready for review May 22, 2025 23:11
@nandan-bhat nandan-bhat requested a review from a team as a code owner May 22, 2025 23:11
@nandan-bhat nandan-bhat merged commit 31c2ce2 into main May 23, 2025
12 checks passed
@nandan-bhat nandan-bhat deleted the fix/gh/issue-2111 branch May 23, 2025 15:46
@tusharpandey13 tusharpandey13 mentioned this pull request Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants