clerk-expo-patterns
Expo Patterns
SDK: @clerk/expo v3+. Requires Expo 53+, React Native 0.73+.
What Do You Need?
| Task | Reference |
|---|---|
| Persist tokens with SecureStore | references/token-storage.md |
| OAuth (Google, Apple, GitHub) | references/oauth-deep-linking.md |
| Protected screens with Expo Router | references/protected-routes.md |
| Push notifications with user data | references/push-notifications.md |
Mental Model
Clerk stores the session token in memory by default. In native apps:
- SecureStore — encrypt token in device keychain (recommended for production)
tokenCache— prop on<ClerkProvider>that provides custom storageuseAuth— same API as web, works in any component- OAuth — requires
useSSO+ deep link scheme configured inapp.json
Minimal Setup
app/_layout.tsx
import { ClerkProvider } from '@clerk/expo'
import { tokenCache } from '@clerk/expo/token-cache'
import { Stack } from 'expo-router'
const publishableKey = process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY!
export default function RootLayout() {
return (
<ClerkProvider publishableKey={publishableKey} tokenCache={tokenCache}>
<Stack />
</ClerkProvider>
)
}
CRITICAL: Use
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY— notNEXT_PUBLIC_. Env vars insidenode_modulesare not inlined in production builds. Always passpublishableKeyexplicitly.
Built-in Token Cache
import { tokenCache } from '@clerk/expo/token-cache'
This uses expo-secure-store with keychainAccessible: AFTER_FIRST_UNLOCK. Install the peer dep:
npx expo install expo-secure-store
Auth Hooks
import { useAuth, useUser, useSignIn, useSignUp, useClerk } from '@clerk/expo'
export function ProfileScreen() {
const { isSignedIn, userId, signOut } = useAuth()
const { user } = useUser()
if (!isSignedIn) return <Redirect href="/sign-in" />
return (
<View>
<Text>{user?.fullName}</Text>
<Button title="Sign Out" onPress={() => signOut()} />
</View>
)
}
OAuth Flow (Google)
import { useSSO } from '@clerk/expo'
import * as WebBrowser from 'expo-web-browser'
WebBrowser.maybeCompleteAuthSession()
export function GoogleSignIn() {
const { startSSOFlow } = useSSO()
const handlePress = async () => {
try {
const { createdSessionId, setActive } = await startSSOFlow({
strategy: 'oauth_google',
redirectUrl: 'myapp://oauth-callback',
})
if (createdSessionId) await setActive!({ session: createdSessionId })
} catch (err) {
console.error(err)
}
}
return <Button title="Continue with Google" onPress={handlePress} />
}
Org Switching
import { useOrganization, useOrganizationList } from '@clerk/expo'
export function OrgSwitcher() {
const { organization } = useOrganization()
const { setActive, userMemberships } = useOrganizationList()
return (
<View>
<Text>Current: {organization?.name ?? 'Personal'}</Text>
{userMemberships.data?.map(mem => (
<Button
key={mem.organization.id}
title={mem.organization.name}
onPress={() => setActive({ organization: mem.organization.id })}
/>
))}
</View>
)
}
Common Pitfalls
| Symptom | Cause | Fix |
|---|---|---|
publishableKey undefined in prod |
Using env var without EXPO_PUBLIC_ |
Rename to EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY |
| Token lost on app restart | No tokenCache |
Pass tokenCache from @clerk/expo/token-cache |
| OAuth redirect not working | Missing scheme in app.json |
Add "scheme": "myapp" to app.json |
WebBrowser.maybeCompleteAuthSession |
Not called | Call it at the top level of the OAuth callback screen |
useSSO not found |
Old @clerk/expo version |
useSSO replaced useOAuth in v3+ |
Import Map
| What | Import From |
|---|---|
ClerkProvider |
@clerk/expo |
tokenCache |
@clerk/expo/token-cache |
useAuth, useUser, useSignIn |
@clerk/expo |
useSSO |
@clerk/expo |
useOrganization, useOrganizationList |
@clerk/expo |
See Also
clerk-setup- Initial Clerk installclerk-custom-ui- Custom flows & appearanceclerk-orgs- B2B organizations
Docs
More from midudev/autoskills
bun
Use when building, testing, and deploying JavaScript/TypeScript applications. Reach for Bun when you need to run scripts, manage dependencies, bundle code, or test applications with a single unified tool.
14pydantic
Python data validation using type hints and runtime type checking with Pydantic v2's Rust-powered core for high-performance validation in FastAPI, Django, and configuration management.
11react-hook-form
React Hook Form performance optimization for client-side form validation using useForm, useWatch, useController, and useFieldArray. This skill should be used when building client-side controlled forms with React Hook Form library. This skill does NOT cover React 19 Server Actions, useActionState, or server-side form handling (use react-19 skill for those).
10azure-deploy
Execute Azure deployments for ALREADY-PREPARED applications that have existing .azure/deployment-plan.md and infrastructure files. DO NOT use this skill when the user asks to CREATE a new application — use azure-prepare instead. This skill runs azd up, azd deploy, terraform apply, and az deployment commands with built-in error recovery. Requires .azure/deployment-plan.md from azure-prepare and validated status from azure-validate. WHEN: \"run azd up\", \"run azd deploy\", \"execute deployment\", \"push to production\", \"push to cloud\", \"go live\", \"ship it\", \"bicep deploy\", \"terraform apply\", \"publish to Azure\", \"launch on Azure\". DO NOT USE WHEN: \"create and deploy\", \"build and deploy\", \"create a new app\", \"set up infrastructure\", \"create and deploy to Azure using Terraform\" — use azure-prepare for these.
8sqlalchemy-orm
SQLAlchemy Python SQL toolkit and ORM with powerful query builder, relationship mapping, and database migrations via Alembic
8clerk
Clerk authentication router. Use when user asks about adding authentication,
8