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.
npm install --save redux-persist-transform-compress-encrypt
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.
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
}
npm run test
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.