maxdeviant/redux-persist-transform-encrypt

Cannot save simple text as state.

mxsxs2 opened this issue · 2 comments

I have a setup where I have multiple reducers and I only persist a part of the state coming from the reducers. For this I have the combineReducers reducers like:

combineReducers(
      reducer1: ...some reducer,
      reducer2: persistReducer({
            key: "foo",
            storage: createIdbStorage({ name: "foo", storeName: "foo" })
            transforms: [createEncryptor({
                secretKey: 'mykey',
            }]
        },
       ...some reducer
      )
)

Default state:

{
 reducer1: {/*some data*/},
 reducer2: {
      bar: {
                 key: "hello"
             },
       my:  "olleh"
     }
}

This persisting and ecrypt/decrypt will cause:

{
 reducer1: {/*some data*/}, //this is untouched as was never persisted
 reducer2: { 
      bar: {
                 key: "hello" //this works 
             },
       my:  null //returns null as JSON.parse cannot parse plain string
     }
}

We could simply add return the decrypted value at sync.js Line:16 instead if a throw error. But that will remove the way how the correctness of the key is checked.

+1😭

Plain strings are now supported in v3.0.0, as shown in this test case.