-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.ts
More file actions
32 lines (27 loc) · 1 KB
/
cache.ts
File metadata and controls
32 lines (27 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { TokenCache } from "@clerk/clerk-expo";
import * as SecureStore from 'expo-secure-store';
import { Platform } from "react-native";
const createTokenCache = (): TokenCache => {
return {
getToken: async (key: string) => {
try {
const item = await SecureStore.getItemAsync(key)
if(item) {
console.log(`${key} was used \n`)
} else {
console.log('No values stored under key: ' + key)
}
return item
} catch (error) {
console.error('secure store get item error: ', error)
await SecureStore.deleteItemAsync(key)
return null
}
},
saveToken: (key: string, token: string) => {
return SecureStore.setItemAsync(key, token)
}
}
}
// SecureStore is not supported on the web
export const tokenCache = Platform.OS !== 'web' ? createTokenCache() : undefined