• Stars
    star
    246
  • Rank 164,726 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

redux-persist-sensitive-storage

npm version CircleCI License

Storage engine to use react-native-sensitive-info with redux-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 is a 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 either yarn or npm. You will also need to install and link react-native-sensitive-info.

Using Yarn:

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

Using npm:

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

Usage

To use redux-persist-sensitive-storage, create a sensitive storage instance using createSensitiveStorage and then configure redux-persist according to its 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. See their documentation for more information.

For redux-persist v5.x or later

import { compose, applyMiddleware, createStore } from "redux";
import { persistStore, persistCombineReducers } from "redux-persist";
import createSensitiveStorage from "redux-persist-sensitive-storage";
import reducers from "./reducers"; // where reducers is an object of reducers

const storage = createSensitiveStorage({
  keychainService: "myKeychain",
  sharedPreferencesName: "mySharedPrefs"
});

const config = {
  key: "root",
  storage,
};

const reducer = persistCombineReducers(config, reducers);

function configureStore () {
  // ...
  let store = createStore(reducer);
  let persistor = 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's Nested Persists support. Your configuration might look something like this:

import { AsyncStorage } from "react-native";
import { combineReducers } from "redux";
import { persistReducer } from "redux-persist";
import createSensitiveStorage from "redux-persist-sensitive-storage";

import { mainReducer, tokenReducer } from "./reducers";

const sensitiveStorage = createSensitiveStorage({
  keychainService: "myKeychain",
  sharedPreferencesName: "mySharedPrefs"
});

const mainPersistConfig = {
  key: "main",
  storage: AsyncStorage,
  blacklist: ["someEphemeralKey"]
};

const tokenPersistConfig = {
  key: "token",
  storage: sensitiveStorage
};

let rootReducer = combineReducers({
  main: persistReducer(mainPersistConfig, mainReducer),
  token: persistReducer(tokenPersistConfig, tokenReducer)
});

For redux-persist v4.x

Modify the persistStore call as follows:

import createSensitiveStorage from "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";
import createSensitiveStorage from "redux-persist-sensitive-storage";

const store = createStore(
  reducer,
  compose(
    applyMiddleware(...),
    autoRehydrate()
  )
);

persistStore(store, {
  storage: createSensitiveStorage({
    keychainService: "myKeychain",
    sharedPreferencesName: "mySharedPrefs"
  });
);

More Repositories

1

hash_diff

Diff tool for deep Ruby hash comparison
Ruby
51
star
2

react-native-appstate-listener

Adapt React Native AppState changes to the React component lifecycle
JavaScript
44
star
3

phoenix-react-apollo-demo

Example app using the Phoenix Framework with React and GraphQL
Elixir
38
star
4

react-boilerplate

Zeal's React/Redux boilerplate setup
JavaScript
35
star
5

redwood-template-app

This is an example application using RedwoodJS. It establishes common patterns for creating an app quickly.
TypeScript
20
star
6

cellulose

[DEPRECATED] React Flexible Contextual Layout Components
JavaScript
17
star
7

skinny

RailsConf 2014 : RSpec Taming Chaotic Specs Workshop
Ruby
17
star
8

robots

Solver for Ricochet Robots
Ruby
16
star
9

RubyConf2014

RubyConf 2014: Rapidly Mapping JSON/XML API Schemas In Ruby (Adam Cuppy)
Ruby
16
star
10

generator-react-zeal

Yeoman generator for Zeal's React boilerplate
JavaScript
14
star
11

super-star-formatters

RailsConf 2014 : RSpec Formatters for the Super Stars
Ruby
12
star
12

zeal-redux-utils

Utility functions for working with Redux
JavaScript
7
star
13

padlock

Lock ActiveRecord objects for editing via Ruby, instead of row locking objects via the database
Ruby
4
star
14

gilded-rose-railsconf2015

Gilded Rose kata for RailsConf2015 legacy code workshop
Ruby
3
star
15

trueman

Easily assert truthy and falsy values on strings, integers. (Not to be confused with #present? and #blank?)
Ruby
3
star
16

eslint-config-zeal

Zeal's ESLint configuration
JavaScript
2
star
17

paperclip-ghostscript

Ruby on Rails Paperclip Processor for Ghostscript
Ruby
2
star
18

thin_notion_api

A thin Notion API package for Elixir that gives you a simple way to communicate with the Notion API
Elixir
2
star
19

webflow-gpt

Lets have AI write some meta descriptions for our blog. Shall we?
JavaScript
2
star
20

google-civic-ruby

Ruby wrapper for the Google Civic API
Ruby
2
star
21

jquery.asyncify.js

Convert standard HTML forms to asynchronous submit via jQuery
CoffeeScript
1
star
22

nextjs-server-action-validation

TypeScript
1
star
23

talk_like_a_x

Elixir
1
star
24

weather-app

A React coding challenge
HTML
1
star