What is expo-secure-store?
The expo-secure-store package provides a way to securely store key-value pairs in a device's secure storage. This is useful for storing sensitive information such as authentication tokens, user preferences, and other confidential data.
What are expo-secure-store's main functionalities?
Storing a value
This feature allows you to store a key-value pair securely. The `setItemAsync` method takes a key and a value as arguments and stores them in the secure storage.
import * as SecureStore from 'expo-secure-store';
async function save(key, value) {
await SecureStore.setItemAsync(key, value);
}
Retrieving a value
This feature allows you to retrieve a value stored under a specific key. The `getItemAsync` method takes a key as an argument and returns the corresponding value.
import * as SecureStore from 'expo-secure-store';
async function getValueFor(key) {
let result = await SecureStore.getItemAsync(key);
if (result) {
console.log("🔐 Here's your value 🔐 \n" + result);
} else {
console.log('No value stored under that key.');
}
}
Deleting a value
This feature allows you to delete a key-value pair from the secure storage. The `deleteItemAsync` method takes a key as an argument and removes the corresponding key-value pair from the storage.
import * as SecureStore from 'expo-secure-store';
async function deleteValueFor(key) {
await SecureStore.deleteItemAsync(key);
}
Other packages similar to expo-secure-store
react-native-keychain
The react-native-keychain package provides similar functionality for securely storing key-value pairs. It supports both iOS and Android and offers additional features such as biometric authentication. Compared to expo-secure-store, react-native-keychain provides more advanced security options but may require more setup.
redux-persist-sensitive-storage
The redux-persist-sensitive-storage package is designed to work with redux-persist to securely store sensitive data. It uses the device's secure storage mechanisms and is a good option if you are already using Redux for state management. Compared to expo-secure-store, it integrates more seamlessly with Redux but is less general-purpose.
secure-store
The secure-store package is another option for securely storing key-value pairs. It is lightweight and easy to use, making it a good alternative to expo-secure-store for simple use cases. However, it may not offer as many features or as much flexibility as expo-secure-store.
expo-secure-store
Provides a way to encrypt and securely store key–value pairs locally on the device.
API documentation
Installation in managed Expo projects
For managed managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release.
Installation in bare React Native projects
For bare React Native projects, you must ensure that you have installed and configured the react-native-unimodules
package before continuing.
Add the package to your npm dependencies
expo install expo-secure-store
Configure for iOS
Run npx pod-install
after installing the npm package.
Configure for Android
No additional set up necessary.
Contributing
Contributions are very welcome! Please refer to guidelines described in the contributing guide.