Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const _clearData = async (key): Promise => {
try {
await AsyncStorage.removeItem(key);
} catch (error) {
logWarn(`Unable to delete data (key = ${key}) from storage.`);
}
try {
await SecureStore.deleteItemAsync(key);
} catch (error) {
logWarn(`Unable to delete data key = ${key} from secure storage.`);
}
};
const _clearData = async (key): Promise => {
try {
await AsyncStorage.removeItem(key);
} catch (error) {
logWarn(`Unable to delete data (key = ${key}) from storage.`);
}
try {
const returnValue = await SecureStore.deleteItemAsync(key);
} catch (error) {
logWarn(`Unable to delete data key = ${key} from secure storage.`);
}
};
}
const noValue =
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);
}
}
}
});
return new Promise(async (resolve, reject) => {
try {
const currentStorageFileUri = await fixedStorageUri(secureStoreOptions);
if (currentStorageFileUri) {
let storageString = await FileSystem.readAsStringAsync(currentStorageFileUri);
storage = JSON.parse(storageString);
delete storage.key;
storageString = JSON.stringify(storage);
const newStorageFileUri = await generateStorageFileUri();
await FileSystem.writeAsStringAsync(newStorageFileUri, storageString);
await SecureStore.setItemAsync(storageFileUriKey, newStorageFileUri, secureStoreOptions);
await FileSystem.deleteAsync(currentStorageFileUri, { idempotent: true });
}
await SecureStore.deleteItemAsync(key, secureStoreOptions);
resolve();
} catch (e) {
reject(e);
}
});
};
_deleteValue = async (key: string) => {
try {
await SecureStore.deleteItemAsync(key, {});
Alert.alert('Success!', 'Value deleted', [
{ text: 'OK', onPress: () => {} },
]);
} catch (e) {
Alert.alert('Error!', e.message, [{ text: 'OK', onPress: () => {} }]);
}
}