refactor(api-client): transparent 401 -> refresh -> retry-once#491
Open
Agbasimere wants to merge 1 commit into
Open
refactor(api-client): transparent 401 -> refresh -> retry-once#491Agbasimere wants to merge 1 commit into
Agbasimere wants to merge 1 commit into
Conversation
Centralizes authenticated fetches, refreshes the session on 401 and retries once, falling back to the session-expiry path on failure.
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.
Description
This PR addresses the issue of spurious failures when a user's
iron-sessionexpires mid-flow. It ensures that the client attempts a transparent session refresh followed by a single retry before gracefully falling back to the standard session-expiry UI.Fixes #484
Changes Made:
POST /api/auth/refreshthat utilizesgetSessionWithRefresh()to safely slide the session window.sessionHandler.refreshSession()which incorporates a shared, deduplicated promise. This guarantees that concurrent 401 responses don't result in parallel refresh requests.401 Unauthorizedresponses inapiClient.tsto attempt a background refresh. If the refresh succeeds, the client retries the failed request immediately with an_isRetryinternal flag to avoid infinite loops.fetch()calls inuseFormAction.ts,app/dashboard/transaction-history/page.tsx, andapp/settings/page.tsxto leverage the enhancedapiClient.tests/session/apiClient.test.ts) validating 200 fast-paths, 401 refresh+retry successes, 401 refresh failures, and non-retry cases like 403. Tokens remain securely out of logs.