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.
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
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>;
Promise<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 reportPlatformsiOSAndroidParameters
| Parameter | Type | Description |
|---|---|---|
| keychainService | string | 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. |
| into | Keychain | The storage that gets the items. Default: `keychain`. The items are written with its options. |
| removeSource | boolean | Delete 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. |
| accessGroup | string | iOS: 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
keychainServicevalues become one storage. Items of different services go to the sameintounder their keys; when two services have the same key, the second is skipped asexists. 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 asrequiresAuth: reading them needs the prompt. Move them withmigrateItem. -
Nothing is overwritten: a key that is taken in
intois skipped asexists. -
Run it before expo-secure-store is used in this launch, or after it is removed, when
removeSourceistrue: two libraries shouldn't work on the same items at once.