Enable offline support in your Expo app
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 theuseAuth()
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.
Use the __experimental_resourceCache
property on ClerkProvider
On <ClerkProvider>
, pass the secureStore
object to the __experimental_resourceCache
property, as shown in the following example:
How to handle network errors
When there is no internet connection, Clerk's custom flows (e.g., signIn.create()
) will throw a network error.
To handle network errors in your Expo app, you can use the isClerkRuntimeError()
function to check if the error is a Clerk-related error. Clerk-related errors are returned as an array of ClerkAPIError
objects. These errors contain a code
property that you can use to identify the specific error. See the following example.
Feedback
Last updated on