UNPKG

1.76 kBJavaScriptView Raw
1import { NativeModules } from 'react-native';
2const { ExponentSecureStore } = NativeModules;
3export const AFTER_FIRST_UNLOCK = ExponentSecureStore.AFTER_FIRST_UNLOCK;
4export const AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY = ExponentSecureStore.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY;
5export const ALWAYS = ExponentSecureStore.ALWAYS;
6export const WHEN_PASSCODE_SET_THIS_DEVICE_ONLY = ExponentSecureStore.WHEN_PASSCODE_SET_THIS_DEVICE_ONLY;
7export const ALWAYS_THIS_DEVICE_ONLY = ExponentSecureStore.ALWAYS_THIS_DEVICE_ONLY;
8export const WHEN_UNLOCKED = ExponentSecureStore.WHEN_UNLOCKED;
9export const WHEN_UNLOCKED_THIS_DEVICE_ONLY = ExponentSecureStore.WHEN_UNLOCKED_THIS_DEVICE_ONLY;
10export async function deleteItemAsync(key, options = {}) {
11 _ensureValidKey(key);
12 await ExponentSecureStore.deleteValueWithKeyAsync(key, options);
13}
14export async function getItemAsync(key, options = {}) {
15 _ensureValidKey(key);
16 return await ExponentSecureStore.getValueWithKeyAsync(key, options);
17}
18export 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}
25function _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}
30function _isValidKey(key) {
31 return typeof key === 'string' && /^[\w.-]+$/.test(key);
32}
33function _isValidValue(value) {
34 return typeof value === 'string';
35}
36//# sourceMappingURL=SecureStore.js.map
\No newline at end of file