Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const _storeData = async (key, value, securely) => {
try {
if (securely) {
// More about options:
// https://docs.expo.io/versions/latest/sdk/securestore/#securestoresetitemasynckey-value-options
const options = { keychainAccessible: SecureStore.WHEN_UNLOCKED };
await SecureStore.setItemAsync(key, value, options);
} else {
await AsyncStorage.setItem(key, value);
}
} catch (error) {
throw Error(`Unable to ${securely ? "securely" : ""} store data.`);
}
};
const _storeData = async (key, value, securely): Promise => {
try {
if (securely) {
// More about options:
// https://docs.expo.io/versions/latest/sdk/securestore/#securestoresetitemasynckey-value-options
const options = { keychainAccessible: SecureStore.WHEN_UNLOCKED };
await SecureStore.setItemAsync(key, value, options);
} else {
await AsyncStorage.setItem(key, value);
}
} catch (error) {
throw Error(`Unable to ${securely ? "securely" : ""} store data.`);
}
};
_setValue = async (value: string, key: string) => {
try {
console.log('securestore: ' + SecureStore);
await SecureStore.setItemAsync(key, value, {});
Alert.alert(
'Success!',
'Value: ' + value + ', stored successfully for key: ' + key,
[{ text: 'OK', onPress: () => {} }]
);
} catch (e) {
Alert.alert('Error!', e.message, [{ text: 'OK', onPress: () => {} }]);
}
}
setItem: (key, value) =>
SecureStore.setItemAsync(replacer(key, replaceCharacter), value, options),
removeItem: key =>
value === null || (typeof value === "string" && !value.length);
const json = JSON.stringify(value);
if (WEB) {
if (User.secureKeys.has(key) || User.persistedKeys.has(key)) {
if (noValue) {
delete localStorage[key];
} else {
localStorage[key] = json;
}
}
} else {
if (User.secureKeys.has(key)) {
if (noValue) {
SecureStore.deleteItemAsync(key);
} else {
SecureStore.setItemAsync(key, json);
}
} else if (User.persistedKeys.has(key)) {
if (noValue) {
AsyncStorage.removeItem(key);
} else {
AsyncStorage.setItem(key, json);
}
}
}
});
.then((json) => {
SecureStore.setItemAsync('ACCESS_TOKEN', json.access_token);
})
.finally(() => callback && callback());