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.

Level: IntermediateWatch: 9 steps · ~45 secondsKeep things, then read the filesRecall: 3 questions · 8 cardsCompare 5 plansTS · SQL

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.

4Compare them all
AsyncStorageasync key-value, kept as plain text
API
OS · Keychain
reads the app's filesreader
the app's filesAsyncStorage: —MMKV: —SQLite: —outside them, the OS'sKeychain / Keystore: —
the app's filesAsync: —MMKV: —SQLite: —Keychain: —
"theme": "dark" → …
Step 1 / 9 · step by step
0secrets in plain text
0 / 0things in the right place
0stores in use

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.

Step 4 · Every option at once, on one clock

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.

Thing 1 / 4: Theme: dark
AsyncStorage for everythingasync key-value, kept as plain textright place 0 of 0

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

StoreGood forNot for
AsyncStoragesettings that aren't secrettokens (plain text), big data
SecureStore / react-native-keychainsmall secrets: tokens, keyslots of data
MMKVsmall values touched all the timesecrets without an encryption key
SQLitelots of data to search and pagesecrets, 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

storage.ts
// 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"]);
}
Run: tsc against each library's own published types (react-native and the libraries this file imports); type-checked only, never run on a phone

AsyncStorage 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.

Table: what goes where

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.