feat(auth): implement single-flight token refresh and cross-tab synchronization - #16
Open
wiliancolomboo-tech wants to merge 2 commits into
Open
Conversation
- coordinate concurrent refresh requests using in-flight Promise sharing - guarantee in-flight reset on both success and failure paths - synchronize cross-tab auth state via BroadcastChannel and storage events - add deterministic unit tests for concurrent deduplication and retry recovery Fixes shaiananvari8#1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR resolves #1 by implementing single-flight token refresh handling and cross-tab state synchronization in
frontend/src/services/auth.ts. Concurrent token refresh calls are deduplicated into a single in-flight Promise, preventing duplicate network requests and race conditions across multiple browser tabs.Changes
refreshTokens()in an in-flight Promise tracker (refreshPromise) that deduplicates concurrent refresh requests and guarantees Promise cleanup in afinallyblock across both success and error paths.BroadcastChannelcoordination (tot_auth_sync) with storage event fallback to notify other tabs on login, logout, refresh success, and refresh failure without broadcasting raw token credentials.frontend/tests/auth.test.mjstesting concurrent refresh deduplication (10 concurrent callers -> 1 HTTP request), failure recovery/retry isolation, and broadcast synchronization metadata compliance.diagnostic/build-d3741f98-part001.logd,diagnostic/build-d3741f98-part002.logd,diagnostic/build-d3741f98-part003.logd,diagnostic/build-d3741f98.json).Diagnostic Decryption Key
Testing
node --test frontend/tests/auth.test.mjsnpm --prefix frontend run buildtsc -b).python3 build.py -m frontendChecklist