Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

redux-persist storage engine for react-native-sensitive-info

License

NotificationsYou must be signed in to change notification settings

CodingZeal/redux-persist-sensitive-storage

Repository files navigation

npm versionCircleCILicense

Storage engine to usereact-native-sensitive-info withredux-persist.

react-native-sensitive-info manages all data stored in Android Shared Preferences and iOS Keychain.

NOTE: Android Shared Preferences are not secure, but there isa branch of react-native-sensitive-info that uses the Android keystore instead of shared preferences. You can use that branch with redux-persist-sensitive-storage if you prefer.

Installation

You can install this package using eitheryarn ornpm. You will also need to install and linkreact-native-sensitive-info.

Using Yarn:

yarn add redux-persist-sensitive-storage react-native-sensitive-inforeact-native link react-native-sensitive-info

Using npm:

npm install --save redux-persist-sensitive-storage react-native-sensitive-inforeact-native link react-native-sensitive-info

Usage

To use redux-persist-sensitive-storage, create a sensitive storage instance usingcreateSensitiveStorage and thenconfigure redux-persist according toits documentation using your instance as the storage argument in the configuration.

createSensitiveStorage takes an optional set of configuration options. These are used to configure the keychain service (iOS) and shared preferences name (Android) that react-native-sensitive-info uses. Seetheir documentation for more information.

For redux-persist v5.x or later

import{compose,applyMiddleware,createStore}from"redux";import{persistStore,persistCombineReducers}from"redux-persist";importcreateSensitiveStoragefrom"redux-persist-sensitive-storage";importreducersfrom"./reducers";// where reducers is an object of reducersconststorage=createSensitiveStorage({keychainService:"myKeychain",sharedPreferencesName:"mySharedPrefs"});constconfig={key:"root",  storage,};constreducer=persistCombineReducers(config,reducers);functionconfigureStore(){// ...letstore=createStore(reducer);letpersistor=persistStore(store);return{ persistor, store};}

You may want to only persist some keys in secure storage, and persist other parts of your state in local storage. If that's the case, you can use redux-persist'sNested Persists support. Your configuration might look something like this:

import{AsyncStorage}from"react-native";import{combineReducers}from"redux";import{persistReducer}from"redux-persist";importcreateSensitiveStoragefrom"redux-persist-sensitive-storage";import{mainReducer,tokenReducer}from"./reducers";constsensitiveStorage=createSensitiveStorage({keychainService:"myKeychain",sharedPreferencesName:"mySharedPrefs"});constmainPersistConfig={key:"main",storage:AsyncStorage,blacklist:["someEphemeralKey"]};consttokenPersistConfig={key:"token",storage:sensitiveStorage};letrootReducer=combineReducers({main:persistReducer(mainPersistConfig,mainReducer),token:persistReducer(tokenPersistConfig,tokenReducer)});

For redux-persist v4.x

Modify thepersistStore call as follows:

importcreateSensitiveStoragefrom"redux-persist-sensitive-storage";// ...persistStore(store,{storage:createSensitiveStorage(options)});

Here is a more complete example:

import{compose,applyMiddleware,createStore}from"redux";import{persistStore,autoRehydrate}from"redux-persist";importcreateSensitiveStoragefrom"redux-persist-sensitive-storage";conststore=createStore(reducer,compose(applyMiddleware(...),autoRehydrate()));persistStore(store,{storage:createSensitiveStorage({keychainService:"myKeychain",sharedPreferencesName:"mySharedPrefs"}););

About

redux-persist storage engine for react-native-sensitive-info

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp