Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add installation and usage documentation to the README #2

Merged
merged 2 commits into from
Jul 13, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,64 @@
[![CircleCI](https://circleci.com/gh/CodingZeal/redux-persist-sensitive-storage.svg?style=shield)](https://circleci.com/gh/CodingZeal/redux-persist-sensitive-storage)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

redux-persist storage engine for react-native-sensitive-info
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).

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

### TODO:
**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.

- [ ] Write documentation
- [ ] How to install (react-native-sensitive-info needs to be installed and `react-native link`-ed)
- [ ] Example of how to use it
- [ ] Describe what options are (same ones accepted by react-native-sensitive-info)
- [ ] Mention that storage is not (yet) secure on Android, but point at branch on r-n-s-i that adds that.
- [ ] Contributing
## Installation

- [x] Add tests
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).

- [ ] Test on both iOS and Android
Using Yarn:
```
yarn add redux-persist-sensitive-storage react-native-sensitive-info
react-native link react-native-sensitive-info
```

- [ ] Submit PR to add a link to this lib from redux-persist
Using npm:
```
npm install --save redux-persist-sensitive-storage react-native-sensitive-info
react-native link react-native-sensitive-info
```

- [ ] Submit PR to add a link to this lib from react-native-sensitive-info
## Usage

To use redux-persist-sensitive-storage, configure redux-persist according to [its documentation](https://github.com/rt2zz/redux-persist#redux-persist).

Modify the `persistStore` call as follows:

```js
import createSensitiveStorage from "redux-persist-sensitive-storage";

// ...

persistStore(store, { storage: createSensitiveStorage(options) });
```

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

Here's a full example:

```js
import { compose, applyMiddleware, createStore } from "redux";
import { persistStore, autoRehydrate } from "redux-persist";
import createSensitiveStorage from "redux-persist-sensitive-storage";

const store = createStore(
reducer,
undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify why you're passing undefined here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I copied the example from the redux-persist docs :-). Looks like it's not needed; I've removed it in 35c4cec

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, awesome. Yeah, I was thinking it was a placeholder for middleware or something, but I see that's actually applied below, inside the compose. This looks great, nice work! 🚢

compose(
applyMiddleware(...),
autoRehydrate()
)
);

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