Skip to content

Conversation

tusharpandey13
Copy link
Contributor

@tusharpandey13 tusharpandey13 commented Jul 25, 2025

This PR adds an Auth0Client flag enableParallelTransactions?: boolean that controls behaviour of SDK for parallel transactions.

This PR also adds some logic to ensure that transaction cookies are cleared in the event of a callback error.

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

📋 Changes

Adds configurable transaction cookie management to prevent accumulation while supporting multi-tab scenarios. New AuthClient constructor options:

  • enableParallelTransactions: boolean (default: true) - Controls single vs multi-transaction mode

Usage example for single-transaction mode:

new AuthClient({
  // ...required options
  enableParallelTransactions: false,
});

Code changes:

  • Changed src/server/auth-client.ts: Added logic to delete transaction cookies after a callback is handled (on success or error).
  • Changed src/server/client.ts: Plumbed the enableParallelTransactions option through to the TransactionStore.
  • Changed src/server/transaction-store.ts: Implemented the logic to handle both single and parallel transaction modes.

Test changes:

  • Changed src/server/auth-client.test.ts: Updated test mocks for new method signatures.
  • Changed src/server/client.test.ts: Added tests to verify enableParallelTransactions is passed correctly.
  • Changed src/server/redundant-txn-cookie-deletion.test.ts: Added an integration test suite with msw to verify the fix for the cookie accumulation bug.

Docs changes:

  • Changed EXAMPLES.md: Added a "Transaction Cookie Configuration" section to document the new feature.
  • Changed README.md: Updated the configuration options table with enableParallelTransactions.
  • Changed V4_MIGRATION_GUIDE.md: Added a section on the new transaction cookie management.

📎 References

#1917
#2209

This PR aims to provide a possible solution to the transaction cookie pileup problem identified in the above issues. While not a complete solution, this can help bridge the gap b/w v3 and v4 behaviour.

Transaction cookies are created everytime startInteractiveLogin (called by handleLogin) redirects for login. These cookies are deleted once the callback handler handleCallback either succeeds or throws and error(added in this change) for the specific transaction state for which it was called.

These transaction cookies are NOT deleted when the callback handler is never called (the user navigates away from the login form (user manually doing this, or a misconfigured setup that ends up in an infinite redirect), in which case the cookies get automatically deleted a/c to their maxAge (this is 1hr by default, another PR will enable configuring this). If enough of these login attempts are cancelled before the txn cookie maxage, cookie storage can fill up.

By using a enableParallelTransactions = false, a single transaction cookie will be used per browser window. If one login transaction is active, trying to login again will fail with a warning.

@tusharpandey13 tusharpandey13 requested a review from a team as a code owner July 25, 2025 11:52
@codecov-commenter
Copy link

codecov-commenter commented Jul 25, 2025

Codecov Report

Attention: Patch coverage is 85.18519% with 8 lines in your changes missing coverage. Please review.

Project coverage is 85.23%. Comparing base (2df00f2) to head (ee2b696).

Files with missing lines Patch % Lines
src/server/transaction-store.ts 66.66% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2244      +/-   ##
==========================================
- Coverage   85.26%   85.23%   -0.04%     
==========================================
  Files          26       26              
  Lines        2409     2451      +42     
  Branches      449      460      +11     
==========================================
+ Hits         2054     2089      +35     
- Misses        349      356       +7     
  Partials        6        6              

☔ 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.

@tusharpandey13 tusharpandey13 changed the title chore: only keep code for enableParallelTransaction flag feat: Add flag to control parallel transactions Jul 25, 2025
@tusharpandey13 tusharpandey13 merged commit 8bb3aa6 into main Jul 28, 2025
12 checks passed
@tusharpandey13 tusharpandey13 deleted the feature/parallel-txn-control branch July 28, 2025 04:56
@tusharpandey13 tusharpandey13 mentioned this pull request Aug 1, 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