maxdeviant/redux-persist-transform-encrypt

when state has string type property, decryption failed

noymer opened this issue · 2 comments

This is #21 explanation.
When state type has string type property, encryption is success, but decryption will be failed.
Here is an example.

// baseReducer output i.e. state is as follows
/*
const state1 = {
  key1: 'string value',
  key2: {
    innerKey: 100,
    innerKey2: 'also string value',
  },
}
*/

const encryptor = createEncryptor({
  secretKey: 'my-super-secret-key'
})

const reducer = persistReducer(
  {
    transforms: [encryptor]
  },
  baseReducer
)

state1 itself is object, but redux-persist persists value per state property.
It is probably because redux-persist config has blacklist whitelist config.
https://github.com/rt2zz/redux-persist/blob/master/docs/api.md#type-persistconfig

When key1: 'string value' is encrypted and decrypted, it is failed.

@noymer Did you fix this for your case?

I encounter the same problem. It seems to work when I change makeEncryptor as follows in helpers.js

if (typeof state !== 'string') { state = (0, _jsonStringifySafe2.default)(state); } return transform(state);

to

return transform((0, _jsonStringifySafe2.default)(state));

So you if you stringify everything (including strings) there is no error. Are there any side effects I'm not aware of? Why is the if case there in the first place?

This should be fixed by v3.0.0.