-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clerk-expo): Improved offline support for Expo (#4604)
- Loading branch information
Showing
97 changed files
with
3,259 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/shared': patch | ||
--- | ||
|
||
Introduce the `errorToJSON` utility function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
'@clerk/clerk-expo': minor | ||
--- | ||
|
||
Introduce improved offline support for Expo. | ||
|
||
We're introducing an improved offline support for the `@clerk/clerk-expo` package to enhance reliability and user experience. This new improvement allows apps to bootstrap without an internet connection by using cached Clerk resources, ensuring quick initialization. | ||
|
||
It solves issues as the following: | ||
|
||
- Faster resolution of the `isLoaded` property and the `ClerkLoaded` component, with only a single network fetch attempt, and if it fails, it falls back to the cached resources. | ||
- The `getToken` function of `useAuth` hook now returns a cached token if network errors occur. | ||
- Developers can now catch and handle network errors gracefully in their custom flows, as the errors are no longer muted. | ||
|
||
How to use it: | ||
|
||
1. Install the `expo-secure-store` package in your project by running: | ||
|
||
```bash | ||
npm i expo-secure-store | ||
``` | ||
|
||
2. Use `import { secureStore } from "@clerk/clerk-expo/secure-store"` to import our implementation of the `SecureStore` API. | ||
3. Pass the `secureStore` in the `__experimental_resourceCache` property of the `ClerkProvider` to enable offline support. | ||
```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> | ||
) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
'@clerk/clerk-js': patch | ||
'@clerk/clerk-react': patch | ||
'@clerk/types': patch | ||
--- | ||
|
||
Introduce a `toJSON()` function on resources. | ||
|
||
This change also introduces two new internal methods on the Clerk resource, to be used by the expo package. | ||
|
||
- `__internal_getCachedResources()`: (Optional) This function is used to load cached Client and Environment resources if Clerk fails to load them from the Frontend API. | ||
- `__internal_reloadInitialResources()`: This funtion is used to reload the initial resources (Environment/Client) from the Frontend API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.