1 | import { NativeModules } from 'react-native';
|
2 | const { ExponentSecureStore } = NativeModules;
|
3 | export const AFTER_FIRST_UNLOCK = ExponentSecureStore.AFTER_FIRST_UNLOCK;
|
4 | export const AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY = ExponentSecureStore.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY;
|
5 | export const ALWAYS = ExponentSecureStore.ALWAYS;
|
6 | export const WHEN_PASSCODE_SET_THIS_DEVICE_ONLY = ExponentSecureStore.WHEN_PASSCODE_SET_THIS_DEVICE_ONLY;
|
7 | export const ALWAYS_THIS_DEVICE_ONLY = ExponentSecureStore.ALWAYS_THIS_DEVICE_ONLY;
|
8 | export const WHEN_UNLOCKED = ExponentSecureStore.WHEN_UNLOCKED;
|
9 | export const WHEN_UNLOCKED_THIS_DEVICE_ONLY = ExponentSecureStore.WHEN_UNLOCKED_THIS_DEVICE_ONLY;
|
10 | export async function deleteItemAsync(key, options = {}) {
|
11 | _ensureValidKey(key);
|
12 | await ExponentSecureStore.deleteValueWithKeyAsync(key, options);
|
13 | }
|
14 | export async function getItemAsync(key, options = {}) {
|
15 | _ensureValidKey(key);
|
16 | return await ExponentSecureStore.getValueWithKeyAsync(key, options);
|
17 | }
|
18 | export async function setItemAsync(key, value, options = {}) {
|
19 | _ensureValidKey(key);
|
20 | if (!_isValidValue(value)) {
|
21 | throw new Error(`Invalid value provided to SecureStore. Values must be strings; consider JSON-encoding your values if they are serializable.`);
|
22 | }
|
23 | await ExponentSecureStore.setValueWithKeyAsync(value, key, options);
|
24 | }
|
25 | function _ensureValidKey(key) {
|
26 | if (!_isValidKey(key)) {
|
27 | throw new Error(`Invalid key provided to SecureStore. Keys must not be empty and contain only alphanumeric characters, ".", "-", and "_".`);
|
28 | }
|
29 | }
|
30 | function _isValidKey(key) {
|
31 | return typeof key === 'string' && /^[\w.-]+$/.test(key);
|
32 | }
|
33 | function _isValidValue(value) {
|
34 | return typeof value === 'string';
|
35 | }
|
36 |
|
\ | No newline at end of file |