Title: @clerk/expo v3 iOS: AuthView session not restored on cold start despite valid JWT in keychain (works on Android, same code) · Issue #8441 · clerk/javascript · GitHub
Open Graph Title: @clerk/expo v3 iOS: AuthView session not restored on cold start despite valid JWT in keychain (works on Android, same code) · Issue #8441 · clerk/javascript
X Title: @clerk/expo v3 iOS: AuthView session not restored on cold start despite valid JWT in keychain (works on Android, same code) · Issue #8441 · clerk/javascript
Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk support via email or Discord This issue ...
Open Graph Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ...
X Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ...
Opengraph URL: https://github.com/clerk/javascript/issues/8441
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"@clerk/expo v3 iOS: AuthView session not restored on cold start despite valid JWT in keychain (works on Android, same code)","articleBody":"### Preliminary Checks\n\n- [x] I have reviewed the documentation: https://clerk.com/docs\n- [x] I have searched for existing issues: https://github.com/clerk/javascript/issues\n- [x] I have not already reached out to Clerk support via email or Discord\n- [x] This issue is not a question, general help request, or anything other than a bug report\n\n### Reproduction\n\nNo standalone repro repo, but reproduces in any Expo SDK 54 + `@clerk/expo` 3.2.7 app on iOS using `\u003cAuthView>` from `@clerk/expo/native`. We've reproduced it in two separate apps in our monorepo (one consumer app, one chat app) with completely different code.\n\n### Publishable key\n\n`pk_live_Y2xlcmsudGhlZGFzaHRhZy5jb20k`\n\n### Description\n\nAfter cold-start (force-quit + relaunch) on **iOS only**, the user's Clerk session is not restored from the JWT in `expo-secure-store`. The same code works perfectly on Android — sessions persist as expected.\n\nSymptoms: user sees the unauthenticated/sign-in screen on every app launch, even though `__clerk_client_jwt` is intact in keychain.\n\n### Environment\n\n| Component | Version |\n|---|---|\n| `@clerk/expo` | 3.2.7 (also reproduced on 3.2.8-canary.v20260501194208) |\n| `clerk-ios` (SwiftPM) | 1.0.0 |\n| Expo SDK | 54 |\n| React Native | 0.81 |\n| iOS (physical device) | 26.3.1 (iPhone 15 Pro Max) |\n| macOS | 26.3 |\n\n### Setup\n\n- `\u003cClerkProvider publishableKey={CLERK_PUBLISHABLE_KEY} tokenCache={tokenCache}>` (default `tokenCache` from `@clerk/expo/token-cache`)\n- `\u003cAuthView mode=\"signInOrUp\" />` from `@clerk/expo/native`\n- `useAuth({ treatPendingAsSignedOut: false })` everywhere\n- `@clerk/expo` plugin in `app.config.ts` plugins array\n- iOS bundle id `com.dashtag.app.dev`, signed with our developer cert\n\n### Diagnosis (with detailed traces)\n\nI patched `node_modules/@clerk/expo/dist/provider/ClerkProvider.js` to add console logging and isolated the bug to native `ClerkExpo.getSession()` returning `undefined` indefinitely after cold-start, despite `configure(pk, jwt)` resolving successfully and a valid JWT being passed.\n\n**Cold-start trace (consistent pattern):**\n\n```text\nmount | isSignedIn=undefined isLoaded=false jwt=eyJhbGciOiJSUzI1NiIs...(len 518)\nbootstrap: calling native configure with bearerToken= eyJhbGciOiJSUzI1NiIs...(len 518)\nbootstrap: configure resolved ← native promise resolves cleanly\nmount | isSignedIn=false isLoaded=true ← Clerk JS finishes loading\nbootstrap: poll #1 getSession() -> undefined\nbootstrap: poll #5 getSession() -> undefined\nbootstrap: poll #15 getSession() -> undefined\nbootstrap: poll #30 getSession() -> undefined\nbootstrap: NO SESSION after 30 polls (3s timeout — original behavior)\n```\n\n**Workaround attempt #1 — extended polling 3s → 30s:** marginal improvement, not reliable.\n\n**Workaround attempt #2 — re-call `configure(pk, jwt)` repeatedly:** sometimes triggers eventual restore (~30% of attempts), but unreliable. After 60s of retries (20 × 3s intervals), `getSession()` still returns `undefined` for fresh sessions created moments before the test.\n\n**Workaround attempt #3 — block spurious `setActive({session: null})`:** never observed this code path being triggered; the bug is purely in `getSession()` returning null.\n\n### What's interesting\n\n1. **Same code, same JWT length, same Clerk user — works on Android, fails on iOS.** I tested side-by-side with the same Metro instance serving both an Android device and an iPhone using the exact same JS bundle. Android: session restored within 1-2s of cold start, every time. iOS: session restored maybe 30% of the time, often never.\n\n2. **The JWT in keychain is fresh and valid.** Just-created sessions (signed in moments before the test) fail to restore.\n\n3. **The `ClerkViewFactory.swift` `syncTokenState` logic looks suspect.** Lines 72-91 of `node_modules/@clerk/expo/ios/ClerkViewFactory.swift` compare the JS-keychain JWT against the `nativeDeviceToken` keychain entry; if they differ, `clearCachedClerkData()` is called to wipe `cachedClient` and `cachedEnvironment`. After the cache wipe, the SDK relies on a network round-trip to repopulate. If that round-trip is slow or fails silently, `Clerk.shared.session` stays nil and `getSession()` returns null. This iOS-specific keychain-dance code does not have an Android equivalent — which matches our observation that Android always works.\n\n4. The `configure()` promise resolving says nothing about whether the session is loaded. `Clerk.shared.session` might still be nil when `configure()` resolves.\n\n### Suggested fix\n\nEither:\n- Make `ClerkExpo.configure(pk, bearerToken)` not resolve until `Clerk.shared.session` is non-nil OR a definitive failure has occurred (currently `waitForLoadedSession()` polls but the promise resolves regardless).\n- Surface an `onAuthStateChange` event when the native SDK eventually loads the session post-`configure()`, so the JS bootstrap can react via `useNativeAuthEvents` instead of polling `getSession()`.\n- Avoid `clearCachedClerkData()` on cold-start when `existingToken == nil` (first-launch case) — only clear when the token actually changed and there's a stale cached client to reconcile.\n\n### Related issues\n\n- #8265 — `@clerk/expo` v3 session not restored on Metro JS reload (Android variant)\n- #8245 — `useAuth().isLoaded` permanently false in v3\n- Both confirm: `@clerk/clerk-expo` v2 did not have these regressions.\n","author":{"url":"https://github.com/brandonatdashtag","@type":"Person","name":"brandonatdashtag"},"datePublished":"2026-05-02T03:17:48Z","url":"https://github.com/clerk/javascript/issues/8441"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:64bc8734-8a59-4086-d4fd-65a240682fb5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BFBC:15DF38:11C81E6:18331F4:6AFB6938 |
| html-safe-nonce | efd0efc2306f756c036c32055bab6d1963b5b01c4fe547facc8bc6f856808c72 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRkJDOjE1REYzODoxMUM4MUU2OjE4MzMxRjQ6NkFGQjY5MzgiLCJ2aXNpdG9yX2lkIjoiNjk5NTQ1NzMxOTc4MTQ5MzA0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b943264ac70e196bc14ef94cb41ac6c210df9b4e271829eb00a0d21b8f167dad |
| hovercard-subject-tag | issue:4367728725 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/clerk/javascript/8441/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1179d3c303eae3f692f454c675990bb88614d1e2c57ea8ba479e07ed04d49981/clerk/javascript/issues/8441 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1179d3c303eae3f692f454c675990bb88614d1e2c57ea8ba479e07ed04d49981/clerk/javascript/issues/8441 |
| og:image:alt | Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brandonatdashtag |
| hostname | github.com |
| expected-hostname | github.com |
| None | ea33d13c96d0ff66bd8fa906b193d2213536b78cb06b0c50a4632c58b1418f94 |
| turbo-cache-control | no-preview |
| go-import | github.com/clerk/javascript git https://github.com/clerk/javascript.git |
| octolytics-dimension-user_id | 49538330 |
| octolytics-dimension-user_login | clerk |
| octolytics-dimension-repository_id | 438331492 |
| octolytics-dimension-repository_nwo | clerk/javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 438331492 |
| octolytics-dimension-repository_network_root_nwo | clerk/javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 59ef97164c52cf59bd10558ddec9c4f482763988 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width