Skip to main content
‹ /migrate
Function

migrateFromExpoSecureStore()

Moves the items of expo-secure-store into this package, under the keys they had. It never shows a prompt; items stored with requireAuthentication are left for migrateItem.

Section/migrateDraftIn the package, not released yet: the API can still change.
Import
import { migrateFromExpoSecureStore } from '@apexnative/keychain/migrate';

expo-secure-store keeps its items where this package doesn't look: Keychain items of its own on iOS, its own preferences and Keystore keys on Android. This function reads them, writes each under the same key into a storage of this package, and reports what it did.

Usage​

src/storage/migrate.ts
import { migrateFromExpoSecureStore } from '@apexnative/keychain/migrate';

const report = await migrateFromExpoSecureStore({ removeSource: true });
// { migrated: ['accessToken', 'refreshToken'], skipped: [], warnings: [] }

SecureStore.getItemAsync('accessToken') becomes keychain.getItem('accessToken').

Signature​

function migrateFromExpoSecureStore(
options?: MigrateFromExpoSecureStoreOptions
): Promise<MigrationReport>;
ReturnsPromise<MigrationReport>PromptNever: a protected item is skipped as requiresAuthThrowsINVALID_ARGUMENT for options that aren't valid; a failure to list the items. A failure of one item is in the reportPlatformsiOSAndroid

Parameters​

ParameterTypeDescription
keychainServicestring | string[]The keychainService option your app passed to expo-secure-store, one or several. Without it, the library's default: app on iOS, key_v1 on Android. With it, those and not the default.
intoKeychainThe storage that gets the items. Default: `keychain`. The items are written with its options.
removeSourcebooleanDelete each old item once the new one is written. With false, it is marked as moved and kept; a later run with true deletes it, if the new item is still there. Default false.
accessGroupstringiOS: move only the items of this access group. Default: every group the app can read.

Returns​

A MigrationReport. Its keys are the items' keys.

Notes​

  • Several keychainService values become one storage. Items of different services go to the same into under their keys; when two services have the same key, the second is skipped as exists. Move each service into a storage of its own when that matters:

    import { createKeychain } from '@apexnative/keychain';

    await migrateFromExpoSecureStore({ keychainService: 'auth', into: createKeychain({ service: 'auth' }) });
  • Protected items (requireAuthentication: true) are skipped as requiresAuth: reading them needs the prompt. Move them with migrateItem.

  • Nothing is overwritten: a key that is taken in into is skipped as exists.

  • Run it before expo-secure-store is used in this launch, or after it is removed, when removeSource is true: two libraries shouldn't work on the same items at once.

See also​