Skip to main content
Docs

Enable offline support in your Expo app

Warning

This is an experimental API.

The __experimental_resourceCache property introduced in this guide is an experimental feature. It is subject to change in future updates, so use it cautiously in production environments. Ensure thorough testing and stay informed through the package's changelog.

The Clerk Expo SDK provides enhanced offline support to improve reliability and user experience. This update enables your app to bootstrap offline using cached Clerk resources, ensuring quick initialization without requiring an internet connection.

It offers the following benefits:

  • Initialization of the Clerk SDK is now more resilient to network failures.
  • Faster resolution of the isLoaded property and the <ClerkLoaded> control component with only a single network fetch attempt. If the fetch fails, it gracefully falls back to cached resources.
  • Network errors are no longer muted, allowing developers to catch and handle them effectively in their custom flows.
  • The getToken() function in the useAuth() hook now supports returning cached tokens, minimizing disruptions caused by network failures.

How to enable offline support

To enable offline support in your Expo app, follow these steps:

Install the necessary peer dependencies

The expo-secure-store package is required to use the offline support feature.

terminal
npm install expo-secure-store
terminal
yarn add expo-secure-store
terminal
pnpm add expo-secure-store

Use the __experimental_resourceCache property on ClerkProvider

On <ClerkProvider>, pass the secureStore object to the __experimental_resourceCache property, as shown in the following example:

app/_layout.tsx
import { ClerkProvider, ClerkLoaded } from '@clerk/clerk-expo'
import { Slot } from 'expo-router'
import { tokenCache } from '../token-cache'
import { secureStore } from '@clerk/clerk-expo/secure-store'

export default function RootLayout() {
  const publishableKey = process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY!

  if (!publishableKey) {
    throw new Error('Add EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY to your .env file')
  }

  return (
    <ClerkProvider
      publishableKey={publishableKey}
      tokenCache={tokenCache}
      __experimental_resourceCache={secureStore}
    >
      <ClerkLoaded>
        <Slot />
      </ClerkLoaded>
    </ClerkProvider>
  )
}

Feedback

What did you think of this content?

Last updated on