Where to keep app data
A setting, a token, 5,000 products and a draft: each has a place on the phone. Put them away, then let someone read the app's files and see what they find.
What you'll take away
- Explain why a token in AsyncStorage is plain text to anyone who reads the app's files
- Keep secrets in SecureStore: the Keychain on iOS, the Keystore on Android
- Put 5,000 products in SQLite and a draft in MMKV, and say why not AsyncStorage
- At sign-out, clear the account's data from every store, and keep the rest
The 1-minute version
Tap a point and the picture below plays that step.
Keep the token in AsyncStorage and read the files, then move it to SecureStore and read them again
What's wrong with keeping the refresh token in AsyncStorage?
The picture: the app on the phone as its user sees it; at the phone's foot, the warehouse that is the app's files on the disk, a room each for AsyncStorage, MMKV and SQLite; up the street, the OS's Keychain vault, outside those files; on the right, someone who can read the files. A model of what each store is made for, not a speed test.
Compare them all: Where the app keeps things
The same four things go into each plan: the theme, the refresh token, 5,000 products and a draft. Then someone reads the app's files. See which plan leaks no secret and keeps everything where it belongs.
Use it when Small settings that aren't secret: theme, language, the last tab opened
Skip it when Tokens, passwords, anything secret (it isn't encrypted), and big data you need to search
A model of what each store is made for, not a speed test. 'Reading the app's files' means a rooted or jailbroken phone, a debug build, or an unencrypted backup. Press any tile to see it large above, with when it fits.
What goes where
| Store | Good for | Not for |
|---|---|---|
| AsyncStorage | settings that aren't secret | tokens (plain text), big data |
| SecureStore / react-native-keychain | small secrets: tokens, keys | lots of data |
| MMKV | small values touched all the time | secrets without an encryption key |
| SQLite | lots of data to search and page | secrets, unless encrypted |
Who can read the app's files
Other apps can't: each app has its own sandbox. But a rooted or jailbroken phone, a debug build, an unencrypted backup or malware with high privileges can. That's why a secret never sits in plain text, however private the folder looks.
Sign-out clears every place
The token, the drafts, cached personal data: wherever the account's things are, sign-out deletes them. Settings that belong to nobody can stay.
In real code
// What goes where: a setting in AsyncStorage, the refresh token in SecureStore, and sign-out clearing the account's things.
import AsyncStorage from "@react-native-async-storage/async-storage";
import * as SecureStore from "expo-secure-store";
// Not secret: plain text is fine.
export async function saveTheme(theme: "light" | "dark"): Promise<void> {
await AsyncStorage.setItem("theme", theme);
}
export async function loadTheme(): Promise<"light" | "dark"> {
return (await AsyncStorage.getItem("theme")) === "light" ? "light" : "dark";
}
// Secret: the Keychain on iOS, encrypted with a Keystore-held key on Android. Never AsyncStorage.
const REFRESH = "refresh_token";
export async function saveRefreshToken(token: string): Promise<void> {
// Readable after the first unlock (a background refresh can use it), and never moved to another device by a backup.
await SecureStore.setItemAsync(REFRESH, token, { keychainAccessible: SecureStore.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY });
}
export const loadRefreshToken = (): Promise<string | null> => SecureStore.getItemAsync(REFRESH);
// Sign-out clears everything that was the account's, wherever it is. The theme is nobody's: it stays.
export async function forgetAccount(): Promise<void> {
await SecureStore.deleteItemAsync(REFRESH);
await AsyncStorage.removeMany(["draft", "last_order"]);
}
tsc against each library's own published types (react-native and the libraries this file imports); type-checked only, never run on a phoneAsyncStorage for the theme, SecureStore for the refresh token, and sign-out clearing what was the account's. Type-checked against the libraries' own types.
Common questions
Is AsyncStorage secure?
No. It keeps plain text, unencrypted. Other apps can't read it, true, but a rooted or jailbroken phone, a debug build and an unencrypted backup can. Use it for settings that aren't secret.
Where should I keep the token?
SecureStore (expo-secure-store) or react-native-keychain: both use the Keychain on iOS and the Keystore on Android, so the token never sits in the app's files as text. The next lesson is how to use those tokens.
Why not keep everything in SecureStore?
It's made for small secrets, not thousands of rows or values read on every render: each read goes through the system. Put lots of data in SQLite, and if it must be encrypted, use a key kept in SecureStore.
MMKV or AsyncStorage?
MMKV for small values touched very often or read synchronously; AsyncStorage is enough for ordinary settings. Neither is encrypted by default. MMKV can be, given a key, and that key goes in SecureStore.
Where do I keep lots of data for offline use?
SQLite (expo-sqlite, for example): rows you can search and sort, reading only what the screen needs. A big JSON blob in AsyncStorage has to be parsed whole every time.
What should sign-out delete?
The token, and everything that belongs to the account, wherever it's kept. Settings that are nobody's, like the theme, can stay.
How do I decide what goes where?
Ask two things: is it secret, and is it big or searched? Secret goes to SecureStore, big to SQLite, touched all the time to MMKV, the rest to AsyncStorage.
Next lesson
Tokens on a phoneLevel: Deep
Tokens live in SecureStore now; next, their whole life: a short access token, refresh, rotation and sign-out.