Native Storage
Secure native key-value storage — TEMP / PERM / SECURE, three tiers
Overview
The Storage Bridge lets your web page read and write data to native storage. Android and iOS use the same JS API.
| Type | Backing store | Cleared when | Use for |
|---|---|---|---|
TEMP | In-memory (Map) | App restarts | Temporary state during a session |
PERM | SharedPreferences (Android) / UserDefaults (iOS) | App uninstall or clearData call | User settings, non-sensitive data |
SECURE | EncryptedSharedPreferences (Android) / Keychain (iOS) | App uninstall or clearSecureData call | Tokens, sessions, PII and other sensitive data |
Storage is isolated per app. Other apps cannot access it.
SECURE tier: Android uses AndroidKeyStore-backed AES256-GCM encryption; iOS uses a Secure Enclave-backed Keychain. On both platforms the data is protected by a hardware security module.
API
saveData
Saves data.
window.unveilyBridge.saveData(key, value, type)
// type: "TEMP" | "PERM" | "SECURE"// Temporary storage (kept only during the session)
window.unveilyBridge.saveData("sessionStep", "2", "TEMP");
// Permanent storage (persists across app restarts)
window.unveilyBridge.saveData("theme", "dark", "PERM");
// Secure storage (encrypted — tokens, sensitive info)
window.unveilyBridge.saveData("accessToken", "eyJ...", "SECURE");loadData
Loads data synchronously. Not usable for the SECURE type — use loadSecureData instead.
const value = window.unveilyBridge.loadData(key, type)
// type: "TEMP" | "PERM"
// Returns: the stored string, or "" if noneconst theme = window.unveilyBridge.loadData("theme", "PERM");
if (theme === "dark") applyDarkMode();loadSecureData
Loads from SECURE storage asynchronously.
window.unveilyBridge.loadSecureData(key, callbackFunctionName)window.unveilyBridge.loadSecureData("accessToken", "onTokenLoaded");
function onTokenLoaded(result) {
if (result.success) {
console.log("Token:", result.value);
} else {
console.log("No stored token");
}
}Callback response structure
{ "success": true, "value": "eyJ..." }
{ "success": false, "value": null }loadData(key, "SECURE") always returns an empty string. Always use loadSecureData to read from SECURE storage.
removeData
Deletes the data for a specific key.
window.unveilyBridge.removeData(key, type)
// type: "TEMP" | "PERM" | "SECURE"window.unveilyBridge.removeData("theme", "PERM");
window.unveilyBridge.removeData("accessToken", "SECURE");clearData
Clears all of TEMP / PERM.
window.unveilyBridge.clearData(type)
// type: "TEMP" | "PERM" | "ALL"window.unveilyBridge.clearData("TEMP"); // Delete all temporary storage
window.unveilyBridge.clearData("PERM"); // Delete all permanent storage
window.unveilyBridge.clearData("ALL"); // Delete both TEMP and PERMclearData does not affect SECURE storage. To delete SECURE data, use clearSecureData.
clearSecureData
Deletes specific keys from SECURE storage.
window.unveilyBridge.clearSecureData(keysJson)
// keysJson: JSON array string of the keys to delete// Delete auth-related keys on logout
window.unveilyBridge.clearSecureData(JSON.stringify(["accessToken", "refreshToken"]));Usage patterns
Login / logout
// After a successful login — store the token in SECURE
async function onLoginSuccess(token, user) {
window.unveilyBridge.saveData("accessToken", token, "SECURE");
window.unveilyBridge.saveData("userProfile", JSON.stringify(user), "PERM");
}
// On app start — load SECURE asynchronously
function checkAuth() {
window.unveilyBridge.loadSecureData("accessToken", "onAuthChecked");
}
function onAuthChecked(result) {
if (result.success && result.value) {
// Handle auto-login
initApp(result.value);
} else {
showLoginScreen();
}
}
// On logout — delete auth data
function logout() {
window.unveilyBridge.clearSecureData(JSON.stringify(["accessToken", "refreshToken"]));
window.unveilyBridge.removeData("userProfile", "PERM");
}Initializing after the glue is ready
window.addEventListener("unveilyGlueReady", () => {
// Access storage only after the bridge is ready
checkAuth();
});