Redux-persist: After purge it stops persisting

Created on 9 Aug 2018  Â·  10Comments  Â·  Source: rt2zz/redux-persist

After purging there are no more calls to persistence. I call purge when user logs-out, but if they re-login Persist does not work anymore. I need to crash the app or refresh the website to start persisting again.

This is happening on React Native as well as in web.

Will post there if so and try to dig more why this is happening.

All 10 comments

@gastonmorixe You shouldn't be calling purge manually. There's something wrong on how you're setting up this library and that's why it's not working consistently. For me it's working perfectly fine and i'm not purging or persisting nothing by hand. Check: https://github.com/rt2zz/redux-persist/issues/579#issuecomment-412571169 , i uploaded my example source code for someone with similar issue

@tommyalvarez I am using https://github.com/rematch/rematch persistor plugin which uses redux-persist under the hood. If you see how they encourage to do this in their tests it's exactly as I am doing, calling purge() after log-out.
I have little control over their configuration.

@gastonmorixe in that case i can't help you much and maybe you should open an issue in that github repository. Nonetheless, i eye peaked that framework and seems that redux-persist comes as a plugin, that is documented and should work out of the box. You don't need to purge anything because when you sign out, you "clear" your session/auth whatever you call it reducer state. That "cleanup" of the session reducer state should end up persisted and hence, the user should not be able to visit authenticable views any more.

You should see in your browser's localstorage console tab, that when you access your app for the first time, you have an initial persisted state under the root key you configured in the plugin. That state is the serialized version initial state of each reducer that is whitelisted for persistance. So... if you reset your session reducer state back to its initialState on log out, everything should be ok

What if I don't want to clear state using a reducer? It's a lot more work to do that instead of just purging the storage.

@waynebloss The persistor.purge method uses a reducer under the hood to clear the state (it actually clears the localStorage and on rehydrate it loads the new 'cleared' state depending on how you set up stateReconciler.

I was just pointing out the general intended way of using this library for the particular use case of _sign out_ and proposing a common used solution, which is clearing your store session state and let redux-persist handle the rest by itself. Anyway, it's impossible to figure out why it's not persisting the state anymore when using purge without seeing initialization code example and the localStorage value after purge. We need more info. @gastonmorixe if you be so kind to provide it :)

I will make a demo soon. Or you might see rematch tests how they purge storage and that’s when it stops working.

Best,

Gaston
323 642 7866

Sent from my iPhone

On Aug 29, 2018, at 1:06 PM, Tomas notifications@github.com wrote:

@waynebloss The persistor.purge method uses a reducer under the hood to clear the state (it actually clears the localStorage and on rehydrate it loads the new 'cleared' state depending on how you set up stateReconciler.

I was just pointing out the general intended way of using this library for the particular use case of sign out and proposing a common used solution, which is clearing your store session state and let redux-persist handle the rest by itself. Anyway, it's impossible to figure out why it's not persisting the state anymore when using purge without seeing initialization code example and the localStorage value after purge. We need more info. @gastonmorixe if you be so kind to provide it :)

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@tommyalvarez Thank you! Much appreciate the explanation.

Thanks @tommyalvarez for your explanation above as well. I opted to use purgeStoredState(config) along with setting reducer state back to initialState to clear state as part of logout.

Any solution ?

Works fine for me

`` persistor.pause() persistor.flush().then(() => { return persistor.purge() }) ```` and then depends on your app logic resume it by persistor.persist()`

e.g in login page ?

Was this page helpful?
0 / 5 - 0 ratings