Skip to content

Instantly share code, notes, and snippets.

Last active September 20, 2018 22:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Redux persistent storage encryption example.
import { combineReducers, createStore, applyMiddleware } from 'redux';
import storage from 'redux-persist/lib/storage';
import { persistReducer, persistStore } from 'redux-persist';
import promise from 'redux-promise';
import createEncryptor from 'redux-persist-transform-encrypt'; // <----- Import createEncryptor
const rootReducer = combineReducers({
myPersistentData: dataReducer,
someMorePresistentData: randomReducer,
Configure your encryptor with the secret key
NOTE: This secret key is required for access to data.
If the key is incorrect or changed after storing data
with some different key, it will return null.
const encryptor = createEncryptor({
secretKey: 'my-not-so-secret-encryption-key',
onError: (error) => {
console.warn('error occured on encryptor', error);
const config = {
key: '_myPersistentDataKey',
/* Add the encryptor as a transform property. This is will
tell the persistent storage to encrypt data using the
configuration given earlier,i.e., our secretKey. */
transforms: [encryptor], // <----- Add this line.
const reducer = persistReducer(config, rootReducer);
const store = createStore(
const persist = persistStore(store);
export default { store, persist };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment