0.1.1 • Published 4 years ago

redux-persist-keychain-storage v0.1.1

Weekly downloads
143
License
-
Repository
github
Last release
4 years ago

redux-persist-keychain-storage

npm version license

Storage engine for redux-persist, which can store sensitive data on the iOS/Android Keychain/Keystore, by wrapping react-native-keychain.

Installation

You should install react-native-keychain alongside this library. For now, v4 is recommended, as v5 on Android requires biometrics to access biometrics (see https://github.com/oblador/react-native-keychain/issues/316), which doesn't allow for a seamless experience when rehydrating the store.

$ yarn add redux-persist-keychain-storage react-native-keychain@^4.0.5

Usage

Persist reducer data on the keychain

The simplest way to use this library is in the default mode, where it stores the reducer data directly in the keychain.

There's a limit to the amount of data that can stored this way, so it's recommended to only use this with very minimal reducers, e.g. one that just stores key authentication data.

import { createKeychainStorage } from 'redux-persist-keychain-storage';

const keychainStorage = createKeychainStorage();

const persistConfig = {
  // Keychain expects a reverse domain name qualifier (app bundle ID) style key
  keyPrefix: 'com.myapp.persist.',
  storage: keychainStorage,
};

const mainReducer = combineReducers({
  token: persistReducer({ ...persistConfig, key: 'token' }),
});

Persist encryption key on the keychain, reducer data encrypted on AsyncStorage

To be implemented, API along lines of: import { createEncryptedStorage } from 'redux-persist-keychain-storage/crypt