Skip to content

Commit 536a4cc

Browse files
authored
Merge pull request #2 from CodingZeal/chores/documentation
Add installation and usage documentation to the README
2 parents 4031b2d + 35c4cec commit 536a4cc

File tree

1 file changed

+53
-13
lines changed

1 file changed

+53
-13
lines changed

README.md

+53-13
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,63 @@
44
[![CircleCI](https://circleci.com/gh/CodingZeal/redux-persist-sensitive-storage.svg?style=shield)](https://circleci.com/gh/CodingZeal/redux-persist-sensitive-storage)
55
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
66

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).
88

9-
More details coming soon!
9+
react-native-sensitive-info manages all data stored in Android Shared Preferences and iOS Keychain.
1010

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.
1212

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
1914

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).
2116

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+
```
2322

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+
```
2528

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

Comments
 (0)