expo-secure-store
- React Native course
- Advanced
- Lesson 37/83
- 5 min
Learn secure storage with expo-secure-store.
The expo-secure-store package
To store sensitive data (password, session token, API key) safely you use the expo-secure-store package. This package wraps the Keychain on iOS and the Keystore on Android; it keeps the data encrypted and app-specific. With Expo you install it with npx expo install expo-secure-store.
AsyncStorage stores data as plain text; so it is not suitable for sensitive data. expo-secure-store writes the data to the device's secure storage; only your app can access it. The package offers three main functions: setItemAsync (write), getItemAsync (read) and deleteItemAsync (delete). All three are asynchronous so they are awaited.
Import
The package comes as a default export: import * as SecureStore from 'expo-secure-store'. This pattern groups all functions under the SecureStore name. Write, read and delete functions are called through this name.
Example: await SecureStore.setItemAsync('token', 'abc123') for writing, const value = await SecureStore.getItemAsync('token') for reading. Values are stored as strings; to store a number or object you first need to convert them to strings. Keys must also be strings; meaningful app-specific names are chosen (like 'token', 'user_id').
Practice Import the package
Complete the empty file. Import the expo-secure-store package with import * as SecureStore. Export it with export { SecureStore }.
Starter code
// import the expo-secure-store package
// export itSample solution
import * as SecureStore from 'expo-secure-store';
export { SecureStore };Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does expo-secure-store provide?
- Only camera
- Only file download
- Encrypted secure storage Correct answer
- Only network requests
Explanation: The package provides encrypted secure storage.
2 Write the import statement
import * as ____ from 'expo-secure-store';
import * as SecureStore from 'expo-secure-store';
Explanation: The SecureStore namespace carries all functions.
3 Match each part to its role
| Term | Meaning |
|---|---|
setItemAsync |
Write |
getItemAsync |
Read |
deleteItemAsync |
Delete |
expo-secure-store |
Package name |