Skip to content

fix: Auto-retry with fresh session on 401 Unauthorized#1166

Open
Exotic209093 wants to merge 2 commits into
tprouvot:releaseCandidatefrom
Exotic209093:fix/session-expired-retry
Open

fix: Auto-retry with fresh session on 401 Unauthorized#1166
Exotic209093 wants to merge 2 commits into
tprouvot:releaseCandidatefrom
Exotic209093:fix/session-expired-retry

Conversation

@Exotic209093

Copy link
Copy Markdown

Summary

  • When a REST API call returns 401 (session expired), automatically attempt to retrieve a fresh session from the browser cookie before showing the error
  • Handles the common case where the user has re-logged into Salesforce in another tab but the extension page still holds the old session

How it works

  1. On 401, request a fresh session from the background script via chrome.runtime.sendMessage
  2. If a new session is available (different from the expired one), update the session and retry the failed request once
  3. If no new session is available, fall through to the existing error handling

The retry is protected by a _sessionRetried flag to prevent infinite loops.

Test Plan

  • Open Data Export and run a query successfully
  • Wait for the session to expire (or clear the session cookie manually)
  • Log back into Salesforce in another tab
  • Return to the Data Export tab and run a query — it should succeed without needing a page refresh
  • If no valid session exists, verify the existing error/toast behavior still works

Closes #1134

When a REST API call returns 401 (session expired), attempt to
retrieve a fresh session from the browser cookie before showing
the error. This handles the case where the user has re-logged into
Salesforce in another tab but the extension page still holds the
old session.

Closes tprouvot#1134
@Exotic209093

Copy link
Copy Markdown
Author

I’ve updated the retry logic to handle both auth modes now.

On a 401, it first checks whether a newer connected-app access token is already available in localStorage, and if not it falls back to fetching a fresher Salesforce sid session from the background script. I also changed the retry to replay the original request cleanly instead of reusing the mutated URL/body from the failed attempt.

I tested the two cases locally:

  • newer connected-app token available: retry succeeds
  • no connected-app token, but fresher sid cookie available: retry succeeds

One limitation remains: this does not silently mint a brand new connected-app token if the stored token is expired and no newer token exists yet. In that case it still falls back to the existing "Generate New Token" flow.

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.

[feat]: Get New Session when Previous Session Has Expired in The Export Query Feature

1 participant