|
4 | 4 | [](https://circleci.com/gh/CodingZeal/redux-persist-sensitive-storage)
|
5 | 5 | [](https://opensource.org/licenses/MIT)
|
6 | 6 |
|
7 |
| -redux-persist storage engine for react-native-sensitive-info |
| 7 | +Storage engine to use [react-native-sensitive-info](https://github.com/mCodex/react-native-sensitive-info) with [redux-persist](https://github.com/rt2zz/redux-persist). |
8 | 8 |
|
9 |
| -More details coming soon! |
| 9 | +react-native-sensitive-info manages all data stored in Android Shared Preferences and iOS Keychain. |
10 | 10 |
|
11 |
| -### TODO: |
| 11 | +**NOTE:** Android Shared Preferences are not secure, but there is [a branch of react-native-sensitive-info](https://github.com/mCodex/react-native-sensitive-info/tree/keystore) that uses the Android keystore instead of shared preferences. You can use that branch with redux-persist-sensitive-storage if you prefer. |
12 | 12 |
|
13 |
| -- [ ] Write documentation |
14 |
| - - [ ] How to install (react-native-sensitive-info needs to be installed and `react-native link`-ed) |
15 |
| - - [ ] Example of how to use it |
16 |
| - - [ ] Describe what options are (same ones accepted by react-native-sensitive-info) |
17 |
| - - [ ] Mention that storage is not (yet) secure on Android, but point at branch on r-n-s-i that adds that. |
18 |
| - - [ ] Contributing |
| 13 | +## Installation |
19 | 14 |
|
20 |
| -- [x] Add tests |
| 15 | +You can install this package using either `yarn` or `npm`. You will also need to install and link [react-native-sensitive-info](https://github.com/mCodex/react-native-sensitive-info). |
21 | 16 |
|
22 |
| -- [ ] Test on both iOS and Android |
| 17 | +Using Yarn: |
| 18 | +``` |
| 19 | +yarn add redux-persist-sensitive-storage react-native-sensitive-info |
| 20 | +react-native link react-native-sensitive-info |
| 21 | +``` |
23 | 22 |
|
24 |
| -- [ ] Submit PR to add a link to this lib from redux-persist |
| 23 | +Using npm: |
| 24 | +``` |
| 25 | +npm install --save redux-persist-sensitive-storage react-native-sensitive-info |
| 26 | +react-native link react-native-sensitive-info |
| 27 | +``` |
25 | 28 |
|
26 |
| -- [ ] Submit PR to add a link to this lib from react-native-sensitive-info |
| 29 | +## Usage |
| 30 | + |
| 31 | +To use redux-persist-sensitive-storage, configure redux-persist according to [its documentation](https://github.com/rt2zz/redux-persist#redux-persist). |
| 32 | + |
| 33 | +Modify the `persistStore` call as follows: |
| 34 | + |
| 35 | +```js |
| 36 | +import createSensitiveStorage from "redux-persist-sensitive-storage"; |
| 37 | + |
| 38 | +// ... |
| 39 | + |
| 40 | +persistStore(store, { storage: createSensitiveStorage(options) }); |
| 41 | +``` |
| 42 | + |
| 43 | +`options` is optional and are used to configure the keychain service (iOS) and shared preferences name (Android) that react-native-sensitive-info uses. See [the documentation](https://github.com/mCodex/react-native-sensitive-info#methods) for more information. |
| 44 | + |
| 45 | +Here's a full example: |
| 46 | + |
| 47 | +```js |
| 48 | +import { compose, applyMiddleware, createStore } from "redux"; |
| 49 | +import { persistStore, autoRehydrate } from "redux-persist"; |
| 50 | +import createSensitiveStorage from "redux-persist-sensitive-storage"; |
| 51 | + |
| 52 | +const store = createStore( |
| 53 | + reducer, |
| 54 | + compose( |
| 55 | + applyMiddleware(...), |
| 56 | + autoRehydrate() |
| 57 | + ) |
| 58 | +); |
| 59 | + |
| 60 | +persistStore(store, { |
| 61 | + storage: createSensitiveStorage({ |
| 62 | + keychainService: "myKeychain", |
| 63 | + sharedPreferencesName: "mySharedPrefs" |
| 64 | + }); |
| 65 | +); |
| 66 | +``` |
0 commit comments