Skip to content

feat: cold-start fetch token-refresh outcome for diagnostics / JS#71

Closed
oferRounds wants to merge 2 commits into
margelo:mainfrom
oferRounds:pr/token-refresh-outcome-tracking
Closed

feat: cold-start fetch token-refresh outcome for diagnostics / JS#71
oferRounds wants to merge 2 commits into
margelo:mainfrom
oferRounds:pr/token-refresh-outcome-tracking

Conversation

@oferRounds
Copy link
Copy Markdown
Contributor

@oferRounds oferRounds commented Apr 11, 2026

Summary

Compared to main: Cold-start native fetch token refresh (before JS runs) records a plaintext last outcome readable from JavaScript, and that value is cleared when fetch token refresh config is cleared.

What changes

  • Android (AutoPrefetcher): Writes nitro_token_refresh_fetch_last_outcome in app prefs when the cold-start path finishes or bails: success, failed_skip, failed_cache, none, not_run, or error.
  • iOS (NitroAutoPrefetcher): Same key in the Nitro fetch UserDefaults suite.
  • JS: getFetchTokenRefreshLastOutcome(): string; clearTokenRefresh('fetch' | 'all') also removes the outcome entry.

Outcome values

success | failed_skip | failed_cache | none | not_run | error | empty string if unset or unreadable.

How to verify

  • Register fetch token refresh, relaunch with a queued autoprefetch, read getFetchTokenRefreshLastOutcome() after startup; confirm it matches the native path and clears after clearTokenRefresh('fetch').

- NitroFetchClient: attach Cookie from CookieManager when request has no Cookie header;
 persist Set-Cookie from responses (including redirects).
- AutoPrefetcher: same for HttpURLConnection token refresh; persist Set-Cookie from refresh response.

Helps SAML/session flows where the session cookie lives in the WebView cookie jar.

Made-with: Cursor
- Android AutoPrefetcher: persist last outcome to SharedPreferences (plaintext key
  nitro_token_refresh_fetch_last_outcome) at each exit: success, failed_skip,
  failed_cache, none, not_run, error.
- iOS NitroAutoPrefetcher: mirror outcome writes to UserDefaults.
- JS: getFetchTokenRefreshLastOutcome(); clearTokenRefresh removes the outcome key.

Depends on Android CookieManager sync PR for a clean AutoPrefetcher history.

Made-with: Cursor
@riteshshukla04
Copy link
Copy Markdown
Collaborator

riteshshukla04 commented Apr 11, 2026

Hey Thanks for the PR!
Can you please break this PR to two different PRs so that changes are atomic.

  1. Cookie Manager
  2. JS one to save the refresh state

@oferRounds
Copy link
Copy Markdown
Contributor Author

oferRounds commented Apr 11, 2026

Thanks! Split into two atomic PRs:

  • CookieManager: #73
  • Token-refresh outcome → JS (draft, stacked): #74

I’ll close this PR in favor of those two.

@oferRounds oferRounds closed this Apr 11, 2026
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.

2 participants