Vue NativeVue Native
Guide
Components
Composables
Navigation
  • iOS
  • Android
  • macOS
GitHub
Guide
Components
Composables
Navigation
  • iOS
  • Android
  • macOS
GitHub
  • Device & System

    • useNetwork
    • useAppState
    • useColorScheme
    • useDeviceInfo
    • useDimensions
    • usePlatform
  • Storage & Files

    • useAsyncStorage
    • useSecureStorage
    • useFileSystem
    • useDatabase
  • Sensors & Hardware

    • useGeolocation
    • useBiometry
    • useHaptics
    • useSensors
    • useBluetooth
  • Media

    • useCamera
    • useAudio
    • useCalendar
    • useContacts
  • Networking

    • useHttp
    • useWebSocket
  • Permissions

    • usePermissions
  • Navigation

    • useBackHandler
    • useSharedElementTransition
  • UI

    • useKeyboard
    • useClipboard
    • useShare
    • useLinking
    • useAnimation
    • useGesture
    • useNotifications
    • useI18n
    • usePerformance
  • Authentication

    • useAppleSignIn
    • useGoogleSignIn
  • Monetization & Updates

    • useIAP
    • useOTAUpdate
    • useBackgroundTask
  • Desktop (macOS)

    • useWindow
    • useMenu
    • useFileDialog
    • useDragDrop

useSecureStorage

Encrypted key-value storage. Backed by Keychain on iOS and EncryptedSharedPreferences on Android. Use this for sensitive data like authentication tokens, API keys, and user credentials.

Usage

<script setup>
import { ref, onMounted } from '@thelacanians/vue-native-runtime'
import { useSecureStorage } from '@thelacanians/vue-native-runtime'

const secureStorage = useSecureStorage()
const token = ref('')

onMounted(async () => {
  token.value = (await secureStorage.getItem('authToken')) ?? ''
})
</script>

API

useSecureStorage(): {
  getItem: (key: string) => Promise<string | null>
  setItem: (key: string, value: string) => Promise<void>
  removeItem: (key: string) => Promise<void>
  clear: () => Promise<void>
}

Return Value

MethodSignatureDescription
getItem(key: string) => Promise<string | null>Retrieve a value by key. Returns null if the key does not exist.
setItem(key: string, value: string) => Promise<void>Store a string value securely under the given key.
removeItem(key: string) => Promise<void>Delete a single key-value pair.
clear() => Promise<void>Remove all secure key-value pairs.

Platform Support

PlatformSupport
iOSBacked by Keychain Services (kSecClassGenericPassword). Data persists across app reinstalls.
AndroidBacked by EncryptedSharedPreferences (AndroidX Security). Uses AES-256 encryption.

Example

<script setup>
import { ref, onMounted } from '@thelacanians/vue-native-runtime'
import { useSecureStorage } from '@thelacanians/vue-native-runtime'

const secureStorage = useSecureStorage()
const isLoggedIn = ref(false)

onMounted(async () => {
  const token = await secureStorage.getItem('authToken')
  isLoggedIn.value = token !== null
})

async function login(token: string) {
  await secureStorage.setItem('authToken', token)
  isLoggedIn.value = true
}

async function logout() {
  await secureStorage.removeItem('authToken')
  isLoggedIn.value = false
}
</script>

<template>
  <VView :style="{ padding: 20 }">
    <VText :style="{ fontSize: 18, marginBottom: 12 }">
      {{ isLoggedIn ? 'Logged in' : 'Logged out' }}
    </VText>
    <VButton :onPress="() => isLoggedIn ? logout() : login('token123')">
      <VText>{{ isLoggedIn ? 'Logout' : 'Login' }}</VText>
    </VButton>
  </VView>
</template>

useSecureStorage vs useAsyncStorage

FeatureuseAsyncStorageuseSecureStorage
BackendUserDefaults / SharedPreferencesKeychain / EncryptedSharedPreferences
EncryptionNoneAES-256
Persists on reinstallNoYes (iOS Keychain)
Use forPreferences, cacheTokens, credentials, secrets
getAllKeys()YesNo

Notes

  • All values must be strings. Serialize objects with JSON.stringify() before storing.
  • Operations run on a background thread and return Promises.
  • On iOS, Keychain items persist across app reinstalls by default. Call clear() on first launch if you want a fresh start after reinstall.
  • This composable has no reactive state and no cleanup -- it returns async functions only.
Edit this page
Last Updated: 2/28/26, 11:24 PM
Contributors: Abdul Hamid, Claude Opus 4.6
Prev
useAsyncStorage
Next
useFileSystem