Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 470
feat(clerk-expo): Add secure token cache implementation and rename secureStore#5375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
32dc6f2
feat(clerk-expo): Export token cache with SecureStore implementation
wobsoriano 7ae835a
chore(clerk-expo): Make expo-secure-store mandatory
wobsoriano 962e8bf
chore(clerk-expo): Add token cache changeset
wobsoriano 4358c56
chore(clerk-expo): Mark secureStore as deprecated in favor of resourc…
wobsoriano 01ba546
chore: update to minor changeset
wobsoriano 4dd9129
chore: update jsdoc
wobsoriano 0bf6ddb
chore: use isNative helper
wobsoriano 8fcdce1
chore: update error message
wobsoriano e7c15de
chore: simplify changeset
wobsoriano 7da3790
chore: highlight package name in changeset
wobsoriano accfd93
chore: update changeset
wobsoriano 020266e
chore: put back expo-secure-store as optional
wobsoriano c87e82f
chore: Add back removed secure-store export
wobsoriano 45e352d
chore: put deprecation directly in secure-store export
wobsoriano 68e8e31
chore: remove unnecessary logging
wobsoriano 9d2902a
chore: reinstall deps
wobsoriano 8403263
chore: update changeset
wobsoriano c4f79cc
test pnpm lock
wobsoriano e539a3c
chore: rerun pnpm install
wobsoriano 8cf248f
fix lockfile
wobsoriano 543a504
run dedupe
wobsoriano 81c632a
chore: sync pnpm-lock.yaml with main
wobsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,24 @@ | ||
| --- | ||
| '@clerk/clerk-expo': minor | ||
| --- | ||
| Adds a secure token cache implementation using `expo-secure-store` which encrypts the session token before storing it. | ||
| Usage: | ||
| ```tsx | ||
| // app/_layout.tsx | ||
| import { ClerkProvider } from '@clerk/clerk-expo' | ||
| import { tokenCache } from '@clerk/clerk-expo/token-cache' | ||
| export default function RootLayout() { | ||
| return ( | ||
| <ClerkProvider | ||
| publishableKey="your-publishable-key" | ||
| tokenCache={tokenCache} | ||
| > | ||
| {/* Your app code */} | ||
| </ClerkProvider> | ||
| ) | ||
| } | ||
| ``` |
This file contains hidden or 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,28 @@ | ||
| --- | ||
| '@clerk/clerk-expo': minor | ||
| --- | ||
| Mark `secureStore` as deprecated in favor of `resourceCache` from `@clerk/clerk-expo/resource-cache`. | ||
| Usage: | ||
| ```tsx | ||
| // app/_layout.tsx | ||
| import { ClerkProvider } from '@clerk/clerk-expo' | ||
| import { tokenCache } from '@clerk/clerk-expo/token-cache' | ||
| // import { secureStore } from '@clerk/clerk-expo/secure-store' | ||
| import { resourceCache } from '@clerk/clerk-expo/resource-cache' | ||
| export default function RootLayout() { | ||
| return ( | ||
| <ClerkProvider | ||
| publishableKey="your-publishable-key" | ||
| tokenCache={tokenCache} | ||
| // __experimental_resourceCache={secureStore} | ||
| __experimental_resourceCache={resourceCache} | ||
| > | ||
| {...} | ||
| </ClerkProvider> | ||
| ) | ||
| } | ||
| ``` |
This file contains hidden or 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 hidden or 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,4 @@ | ||
| { | ||
| "main": "../dist/resource-cache/index.js", | ||
| "types": "../dist/resource-cache/index.d.ts" | ||
| } |
File renamed without changes.
28 changes: 14 additions & 14 deletions
28 ...cure-store/__tests__/secure-store.test.ts → ...urce-cache/__tests__/secure-store.test.ts
This file contains hidden or 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 hidden or 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 @@ | ||
| export { createResourceCacheStore as resourceCache } from './resource-cache'; |
2 changes: 1 addition & 1 deletion
2 ...ges/expo/src/secure-store/secure-store.ts → ...expo/src/resource-cache/resource-cache.ts
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,8 @@ | ||
| export { createSecureStore as secureStore } from './secure-store'; | ||
| import { resourceCache } from '../resource-cache'; | ||
| /** | ||
| * @deprecated Use `resourceCache` from `@clerk/clerk-expo/resource-cache` instead. | ||
| */ | ||
| const secureStore = resourceCache; | ||
| export { secureStore }; | ||
This file contains hidden or 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,39 @@ | ||
| import * as SecureStore from 'expo-secure-store'; | ||
| import type { TokenCache } from '../cache'; | ||
| import { isNative } from '../utils'; | ||
| /** | ||
| * Create a token cache using Expo's SecureStore | ||
| */ | ||
| const createTokenCache = (): TokenCache => { | ||
| return { | ||
| getToken: async (key: string) => { | ||
| try { | ||
| const item = await SecureStore.getItemAsync(key); | ||
| return item; | ||
| } catch { | ||
| await SecureStore.deleteItemAsync(key); | ||
| return null; | ||
| } | ||
| }, | ||
| saveToken: (key: string, token: string) => { | ||
| return SecureStore.setItemAsync(key, token); | ||
| }, | ||
| }; | ||
| }; | ||
| /** | ||
| * Secure token cache implementation for Expo apps. | ||
| * | ||
| * Clerk stores the active user's session token in memory by default. In Expo apps, the | ||
| * recommended way to store sensitive data, such as tokens, is by using `expo-secure-store` | ||
| * which encrypts the data before storing it. | ||
| * | ||
| * To implement your own token cache, create an object that implements the `TokenCache` interface: | ||
| * - `getToken(key: string): Promise<string | null>` | ||
| * - `saveToken(key: string, token: string): Promise<void>` | ||
| * | ||
| * @type {TokenCache | undefined} Object with `getToken` and `saveToken` methods, undefined on web | ||
| */ | ||
| export const tokenCache = isNative() ? createTokenCache() : undefined; |
This file contains hidden or 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,4 @@ | ||
| { | ||
| "main": "../dist/token-cache/index.js", | ||
| "types": "../dist/token-cache/index.d.ts" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.