Storage.getItem
Asynchronously reads the string value at the given key. Resolves to null when the key is missing — distinct from an empty string ('').
This page is community-written. The SDK behavior itself is defined by the upstream @apps-in-toss/web-framework release.
Signature
import { Storage } from '@apps-in-toss/web-framework';
declare const Storage: {
getItem(key: string): Promise<string | null>;
// ...see overview
};
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
key | string | ✓ | The key to read. Must match exactly the key the mini-app wrote with setItem. |
Returns
Promise<string | null>— the stored string, ornullif the key doesn't exist.
null ≠ empty stringnull means the key was never written, or has been deleted via removeItem/clearItems. An empty string ('') is the result of explicitly storing an empty value — the two are distinct. Compare with value === null rather than !value (the latter swallows '').
Permission
No permission required — the Storage namespace is not bound to a PermissionName. For the typical permission flow used by other namespaces, see Guides — Permissions pattern.
Examples
Minimal
import { Storage } from '@apps-in-toss/web-framework';
const lastSeen = await Storage.getItem('user.lastSeenScreen');
console.log(lastSeen ?? 'home'); // first visit → fall back to 'home'
Realistic — safely restoring a serialized object
import { Storage } from '@apps-in-toss/web-framework';
interface UserPrefs {
theme: 'light' | 'dark';
language: string;
}
const DEFAULT_PREFS: UserPrefs = { theme: 'light', language: 'ko' };
async function loadPrefs(): Promise<UserPrefs> {
const raw = await Storage.getItem('user.prefs');
if (raw === null) return DEFAULT_PREFS;
try {
const parsed = JSON.parse(raw) as Partial<UserPrefs>;
// Older versions may have only written some fields — fill in defaults.
return { ...DEFAULT_PREFS, ...parsed };
} catch {
// Broken format or stale schema — fall back to defaults.
return DEFAULT_PREFS;
}
}
Try it live
Open the Storage page in sdk-example and run the getItem card to inspect the result.
Related APIs
Storage.setItem— store a value.Storage.removeItem— delete a single key.Storage.clearItems— delete every key the mini-app has stored.
Related guides
- Guides — Permissions pattern — permission flow used by other namespaces (reference only;
Storageitself doesn't require a permission). - (coming soon) Recipes — "User preferences pattern (serialization, migration, defaults)"
External references
@apps-in-toss/web-framework— SDK package. The actual exports are re-exported from@apps-in-toss/web-bridge.- Web standard counterpart:
Storage.getItem(localStorage) — synchronous in the standard; both returnnullwhen the key is absent.