Cookie Sync (Android)
Bridges Android's WebView CookieManager with nitro-fetch's Cronet client and the cold-start token-refresh path. Useful when your auth flow stores the session cookie in the WebView cookie jar (e.g. SAML, OAuth login pages rendered in a WebView) and you need subsequent native fetches to send it.
When enabled:
- Outbound requests: if the request has no
Cookieheader, the matching cookies fromCookieManagerare attached for the request URL. - Inbound responses: any
Set-Cookieheaders (including those returned during redirects) are stored back intoCookieManager. Persistence is flushed once per request after the final response.
User-set Cookie headers are always respected — sync never overwrites them.
Enable
Cookie sync is opt-in and disabled by default. Enable it once from your Application.onCreate() (or any code path that runs before the first fetch / auto-prefetch):
// android/app/src/main/java/.../MainApplication.kt
import com.margelo.nitro.nitrofetch.NitroCookieSync
class MainApplication : Application(), ReactApplication {
override fun onCreate() {
super.onCreate()
NitroCookieSync.enableCookieSync()
// ...rest of your onCreate
}
}
That's it — both the Cronet client (fetch) and the HttpURLConnection token-refresh path will start syncing cookies on the next request.
Notes
- Android only. iOS
URLSessionalready shares cookies withWKWebViewviaHTTPCookieStorageand needs no opt-in. - Token-refresh redirects:
HttpURLConnectionfollows redirects internally and only the final response'sSet-Cookieheaders are visible. If your refresh endpoint sets cookies on a 3xx hop, point it directly at the final URL.