fix(auth): add single-flight token refresh handling and cross-tab sync (fixes #1) - #18
Open
wiliancolomboo-tech wants to merge 3 commits into
Conversation
added 3 commits
September 1, 2026 23:40
…-tab auth state
- Implement single-flight in-flight promise coalescing in refreshTokens()
- Add cross-tab authentication state sync via BroadcastChannel ('tot_auth_channel')
- Add storage event listener fallback for cross-tab token synchronization
- Include required diagnostic build log artifacts
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
Fixes #1
This PR resolves the token refresh concurrency race condition in the authentication service (
frontend/src/services/auth.ts). When multiple browser tabs or concurrent API callers attempt to refresh tokens simultaneously, requests are now coalesced into a single in-flightPromise<AuthTokens | null>. In addition, authentication state updates (LOGIN,LOGOUT,REFRESH_SUCCESS,REFRESH_FAILURE) are synchronized across open tabs usingBroadcastChannelwith awindow.storageevent listener fallback, without exposing sensitive raw tokens.Changes
inFlightRefreshpromise tracker infrontend/src/services/auth.tsto ensure concurrent callers share the exact same active refresh operation and receive identical resolved session tokens.inFlightRefreshis reset in afinallyblock on both success and failure, ensuring subsequent token renewals can execute cleanly.BroadcastChannel('tot_auth_channel')andwindow.addEventListener('storage')to notify other browser contexts of auth state transitions (REFRESH_SUCCESS,REFRESH_FAILURE,LOGIN,LOGOUT) without transmitting raw JWT tokens over message payloads.auth.tsmodule documentation detailing concurrency guarantees and cross-tab behavior.python3 build.pyand committed diagnostic artifacts indiagnostic/.Testing
npm run build/tsc -b && vite buildpassed 100%).python3 build.pyto generate and commit diagnostic log chunks (diagnostic/build-d6e2059c*.logdanddiagnostic/build-d6e2059c.json).Checklist