SecureStore helps you save secret information safely on a phone. It keeps passwords or tokens hidden from others.
Saving a user's login password securely.
Storing an API token for accessing a web service.
Keeping a secret key for encrypting data.
Remembering user preferences that should stay private.
Syntax
React Native
import * as SecureStore from'expo-secure-store';
// Save data
await SecureStore.setItemAsync(key, value);
// Get data
const result = await SecureStore.getItemAsync(key);
// Delete data
await SecureStore.deleteItemAsync(key);
Use setItemAsync to save data securely.
Use getItemAsync to read saved data.
Examples
Saves the token 'abc123' under the key 'userToken'.
The code saves the string 'abc123' under the key 'token'.
Step 2: Retrieve the saved value with getItemAsync
Then it fetches the value for 'token', which returns 'abc123'.
Final Answer:
'abc123' -> Option A
Quick Check:
Save then get returns saved string [OK]
Hint: getItemAsync returns saved value if key exists [OK]
Common Mistakes:
Expecting undefined or null instead of saved value
Confusing method names or forgetting await
Assuming error if key exists
4. Identify the error in this code snippet that tries to delete a stored item:
SecureStore.deleteItem('userPassword');
medium
A. Method name should be deleteItemAsync and must be awaited
B. Key 'userPassword' must be a number, not string
C. deleteItem does not exist; use removeItem instead
D. No error; code is correct
Solution
Step 1: Check method name for deleting data
The correct method is deleteItemAsync, not deleteItem.
Step 2: Remember async methods require await
Since it returns a promise, it should be called with await.
Final Answer:
Method name should be deleteItemAsync and must be awaited -> Option A
Quick Check:
Delete method = deleteItemAsync with await [OK]
Hint: Use deleteItemAsync with await to remove data [OK]
Common Mistakes:
Using wrong method name deleteItem
Not awaiting async calls
Thinking key must be a number
5. You want to securely store a user's session token and then immediately retrieve it to verify. Which code snippet correctly does this with error handling?
hard
A. SecureStore.setItem('session', token);
const saved = SecureStore.getItem('session');
console.log(saved);