Agent Skillsmidudev/autoskills › clerk-expo-patterns

clerk-expo-patterns

GitHub

提供Expo/React Native集成Clerk的认证模式,涵盖SecureStore令牌缓存、OAuth深度链接、原生useAuth及Expo Router受保护路由。

packages/autoskills/skills-registry/clerk-expo-patterns/SKILL.md midudev/autoskills

Trigger Scenarios

expo clerk clerk react native SecureStore token cache expo router auth OAuth deep link clerk mobile auth clerk

Install

npx skills add midudev/autoskills --skill clerk-expo-patterns -g -y
More Options

Non-standard path

npx skills add https://github.com/midudev/autoskills/tree/main/packages/autoskills/skills-registry/clerk-expo-patterns -g -y

Use without installing

npx skills use midudev/autoskills@clerk-expo-patterns

指定 Agent (Claude Code)

npx skills add midudev/autoskills --skill clerk-expo-patterns -a claude-code -g -y

安装 repo 全部 skill

npx skills add midudev/autoskills --all -g -y

预览 repo 内 skill

npx skills add midudev/autoskills --list

SKILL.md

Frontmatter
{
    "name": "clerk-expo-patterns",
    "license": "MIT",
    "metadata": {
        "author": "clerk",
        "version": "1.0.0"
    },
    "description": "Expo \/ React Native patterns with Clerk — SecureStore token cache, OAuth deep linking, useAuth in native, Expo Router protected routes, push notifications with user context. Triggers on: expo clerk, clerk react native, SecureStore token cache, expo router auth, OAuth deep link clerk, mobile auth clerk.",
    "allowed-tools": "WebFetch",
    "compatibility": "Requires Expo CLI and expo-secure-store package"
}

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 storage
  • useAuth — same API as web, works in any component
  • OAuth — requires useSSO + deep link scheme configured in app.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 — not NEXT_PUBLIC_. Env vars inside node_modules are not inlined in production builds. Always pass publishableKey explicitly.

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 install
  • clerk-custom-ui - Custom flows & appearance
  • clerk-orgs - B2B organizations

Docs

Expo SDK

Version History

  • 0ec7253 Current 2026-07-24 20:52

Same Skill Collection

packages/autoskills/skills-registry/accessibility/SKILL.md
packages/autoskills/skills-registry/adev-writing-guide/SKILL.md
packages/autoskills/skills-registry/agents-sdk/SKILL.md
packages/autoskills/skills-registry/android-architecture-clean/SKILL.md
packages/autoskills/skills-registry/android-compose-foundations/SKILL.md
packages/autoskills/skills-registry/android-coroutines-flow/SKILL.md
packages/autoskills/skills-registry/android-di-hilt/SKILL.md
packages/autoskills/skills-registry/android-gradle-build-logic/SKILL.md
packages/autoskills/skills-registry/android-kotlin-core/SKILL.md
packages/autoskills/skills-registry/android-networking-retrofit-okhttp/SKILL.md
packages/autoskills/skills-registry/android-testing-unit/SKILL.md
packages/autoskills/skills-registry/angular-developer/SKILL.md
packages/autoskills/skills-registry/aspnet-core/SKILL.md
packages/autoskills/skills-registry/aspnet-minimal-api-openapi/SKILL.md
packages/autoskills/skills-registry/astro/SKILL.md
packages/autoskills/skills-registry/azure-ai/SKILL.md
packages/autoskills/skills-registry/bash-defensive-patterns/SKILL.md
packages/autoskills/skills-registry/best-practices/SKILL.md
packages/autoskills/skills-registry/building-native-ui/SKILL.md
packages/autoskills/skills-registry/bun/SKILL.md
packages/autoskills/skills-registry/chrome-extension-development/SKILL.md
packages/autoskills/skills-registry/clerk-android/SKILL.md
packages/autoskills/skills-registry/clerk-astro-patterns/SKILL.md
packages/autoskills/skills-registry/clerk-backend-api/SKILL.md
packages/autoskills/skills-registry/clerk-chrome-extension-patterns/SKILL.md
packages/autoskills/skills-registry/clerk-custom-ui/SKILL.md
packages/autoskills/skills-registry/clerk-nextjs-patterns/SKILL.md
packages/autoskills/skills-registry/clerk-nuxt-patterns/SKILL.md
packages/autoskills/skills-registry/clerk-orgs/SKILL.md
packages/autoskills/skills-registry/clerk-react-patterns/SKILL.md
packages/autoskills/skills-registry/clerk-react-router-patterns/SKILL.md
packages/autoskills/skills-registry/clerk-setup/SKILL.md
packages/autoskills/skills-registry/clerk-swift/SKILL.md
packages/autoskills/skills-registry/clerk-tanstack-patterns/SKILL.md
packages/autoskills/skills-registry/clerk-testing/SKILL.md
packages/autoskills/skills-registry/clerk-vue-patterns/SKILL.md
packages/autoskills/skills-registry/clerk-webhooks/SKILL.md
packages/autoskills/skills-registry/cloudflare-deploy/SKILL.md
packages/autoskills/skills-registry/cloudflare/SKILL.md
packages/autoskills/skills-registry/composition-patterns/SKILL.md
packages/autoskills/skills-registry/containerize-aspnetcore/SKILL.md
packages/autoskills/skills-registry/core-data-expert/SKILL.md
packages/autoskills/skills-registry/csharp-docs/SKILL.md
packages/autoskills/skills-registry/csharp-mstest/SKILL.md
packages/autoskills/skills-registry/csharp-nunit/SKILL.md
packages/autoskills/skills-registry/csharp-tunit/SKILL.md
packages/autoskills/skills-registry/csharp-xunit/SKILL.md
packages/autoskills/skills-registry/dart-best-practices/SKILL.md
packages/autoskills/skills-registry/deno-deploy/SKILL.md

Metadata

Files
0
Version
0ec7253
Hash
bc8f30d9
Indexed
2026-07-24 20:52

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-07 04:24
浙ICP备14020137号-1 $방문자$