maxdeviant/redux-persist-transform-encrypt

need some example about the transform

geminiyellow opened this issue · 7 comments

hi @maxdeviant ,

thanks for your work. but i think i cannot use this transform follow your example in docs.

i create a new project, and use redux-persist, it work well.
but when i use the transform,

Uncaught TypeError: Cannot read property 'settings' of undefined

could you give me a workable demo project ?

Are you able to show me the relevant sections of your code? I could take a look at it to see if anything looks out of the ordinary.

I will also look into putting together an example usage project 👍

@maxdeviant

I think I know why this problem occurs. because I use multi transform in one time,

immutable - support immutable reducers
compress - compress your serialized state with lz-string
encrypt - encrypt your serialized state with AES

immutable -> compress is ok,
but when compress -> immutable, you know, immutable will output something like '^', compress will parse it as a single key. so, the hole data tree is break.

I'm also trying to use the immutable transform with the encrypt transform and am getting errors with the compress -> immutable step. @geminiyellow: did you find a way around the problem?

@alexsbryan Perhaps I am a little confused. Does the compress -> immutable step work without the encryption? Or does it just not work at all?

Sorry I posted too hastily, forget I said anything about compress -- I'm only trying to use the encrypt transform and the immutable transform. So for me the immutable store is getting encrypted, but when trying to rehydrate from persistence I'm getting errors and the state I observe instead of looking like ImmutableMap looks like ["~#iM", Array].

I think I may have found the issue.

It looks like the immutable transform returns the raw value unless the persisted state is a string:

function(raw){
  if(typeof raw === 'string'){
    return transitInstance.fromJSON(raw)
  }
  return raw
},

The encrypt transform returns its state as an object:

var newState = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
return newState;

Which means that a plain JS object is being passed back instead of an Immutable object.

I based my transform heavily on the compress transform, which behaves the same way, which leads me to believe that the immutable transform may need to be updated.

@rt2zz Perhaps you can shed some light on this?

Closing this out due to age.

Example usage can be found in the end-to-end tests.