fix(expo): prevent session loss on Expo JS reload#8437
fix(expo): prevent session loss on Expo JS reload#8437souyahia wants to merge 1 commit intoclerk:mainfrom
Conversation
NativeSessionSync was calling native signOut() during the loading phase when isSignedIn is undefined (!undefined === true). On a JS reload (pressing R in Expo), the native module persists from the previous session, so signOut() goes through and revokes the session server-side via Clerk.shared.auth.signOut() and clears all keychain items via Clerk.clearAllKeychainItems(), forcing the user to log in again. On a full app restart (kill + reopen), the native module factory is uninitialized (process died), so signOut() rejects with E_NOT_INITIALIZED and the session is preserved. This adds an isLoaded guard so native signOut() is only called when Clerk has fully loaded and confirmed the user is actually signed out, not during the initial loading phase.
|
@souyahia is attempting to deploy a commit to the Clerk Production Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: adda444 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR introduces a changeset and updates the ClerkProvider component in the Expo package to fix premature sign-out calls during JavaScript reloads. The Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
Summary
Fixes a bug where pressing R (JS reload) in Expo during development causes the user's session to be lost, forcing them to log in again. Killing and reopening the app preserves the session correctly.
Root cause
NativeSessionSynccallsClerkExpo.signOut()wheneverisSignedInis falsy, without checking whether Clerk has finished loading:On a JS reload (pressing R in Expo):
NativeSessionSyncmounts,useAuth()returnsisSignedIn: undefined(loading)!undefined === true, so it enters the signed-out branchClerkExpo.signOut()is called on the native module, which is still configured from the previous sessionsignOut()callsClerk.shared.auth.signOut(sessionId:)(revoking the session server-side) andClerk.clearAllKeychainItems()(deleting the JWT from the keychain)On a full app restart (kill + reopen), the native module's factory is uninitialized (the process died), so
signOut()rejects withE_NOT_INITIALIZEDand the session is preserved correctly.Fix
Added an
isLoadedguard soClerkExpo.signOut()is only called when Clerk has fully loaded and confirmed the user is actually signed out, not during the initial loading phase.