feat(auth): add request deduplication for concurrent session operations #1970
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat(auth): add request deduplication for concurrent session operations
🔍 Description
This PR implements request deduplication to prevent redundant concurrent network requests during authentication operations, specifically for session fetching and recovery operations.
What changed?
getSessionDeferredproperty to deduplicate concurrent getSession() callsrecoveringDeferredproperty to deduplicate concurrent _recoverAndRefresh() operations during initialization##Key Implementation Details:
Deferredutility class for promise coordinationWhy was this change needed?
Problem:
When multiple parts of an application call getSession() simultaneously (e.g., during app initialization, route guards, or component mounting), each call would trigger a separate network request to the auth server. This leads to:
Solution:
By implementing request deduplication, we ensure that concurrent calls to the same operation share a single network request, significantly reducing overhead while maintaining the same API behavior.
Closes #1966
📸 Screenshots/Examples
Test Output
The test-concurrent-requests.ts file demonstrates the improvement: