redux-persist-transform-compress-encrypt
v1.0.2
Published
compress and encrypt your redux state
Downloads
226
Maintainers
Readme
redux-persist-transform-compress-encrypt
To persist a compressed and encrypted Redux store
The package creates a transformer for redux-persist. The transformer stringifies the inbound state, compresses it using lz-string
and encrypts the compressed string with AES.
Installation
npm install --save redux-persist-transform-compress-encrypt
Usage
import { persistReducer } from 'redux-persist'
import createCompressEncryptor from 'redux-persist-transform-compress-encrypt'
const transformer = createCompressEncryptor({
secretKey: 'secret-key',
onError: function(error) {
//fired whenever there is any issue with transformation,
//compression or encryption/decryption
}
})
const reducer = persistReducer({ transforms: [transformer] }, baseReducer)
If the package encounters anything unexpected, it skips the transformation, called onError and returns the state as it received.
Config
Here are all the keys you can pass to createCompressEncryptor
.
interface TransformConfigType {
//The whitelist and blacklist keys are passed as it is to the
//createTransform function
whitelist?: Array<string>
blacklist?: Array<string>
//key for encryption/decryption
secretKey: string
//if any error occurs during transformation, this function is called
onError?: (e: Error) => void
}
Test
npm run test
Notes
This package is technically bundling the packages redux-persist-transform-compress
and redux-persist-transform-encrypt
into one. Personally, I could not get them to work together and found it easier to just create my own transform.