Skip to content

feat: expose cold-start fetch token-refresh outcome to JS#74

Draft
oferRounds wants to merge 3 commits intomargelo:mainfrom
oferRounds:pr/cold-start-token-refresh-outcome-js
Draft

feat: expose cold-start fetch token-refresh outcome to JS#74
oferRounds wants to merge 3 commits intomargelo:mainfrom
oferRounds:pr/cold-start-token-refresh-outcome-js

Conversation

@oferRounds
Copy link
Copy Markdown
Contributor

@oferRounds oferRounds commented Apr 11, 2026

Review note

Until #73 is in main, Files changed here includes cookie + outcome (both target main; the cookie branch only exists on the fork). Outcome-only diff: oferRounds/react-native-nitro-fetch#1.

Summary

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

Outcome values: success | failed_skip | failed_cache | none | not_run | error | empty string if unset.

Merge order

Merge #73 first, then rebase this branch onto main so the upstream diff is outcome-only.

Split from #71

Atomic PR 2 of 2 per review on #71.

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
- NitroCookieSync: shared attach + Set-Cookie helpers; flush only when cookies applied
- Cronet: apply Set-Cookie on redirects without flush; flush once on success when
  redirects or final response stored cookies
- HttpURLConnection token refresh: reuse attach helper; Set-Cookie + flush only if needed

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
@oferRounds oferRounds force-pushed the pr/cold-start-token-refresh-outcome-js branch from b2927ee to 04f649a Compare April 12, 2026 08:02
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.

1 participant