RFC add a CLEAR action #150
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MichaelContento/redux-storage#150
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Right now we've got LOAD and SAVE, but what happens if a person logs out? Chances are, we'll want a CLEAR.
Thoughts?
redux-storagesimply reflects the state store in yourreduxapplication. So if the users logs out your state should already reflect this change, right? And if this is the case the user should be logged out forredux-storagetoo. As long as theSAVEaction has not been prevented (e.g. white- / blacklisting or a fast browser reload in combination with a high debounce time).Or is there a special case I'm missing?
Yeah, I think the alternative is to write a null reducer & call
store.replaceReducer(nullReducer). It's not bad, but it's something I'd only ever do if I were persisting the state, so it'd be great to lift that out of the application logic & into the persist logic.But .. uhm .. well
replaceReduceris an advanced API that you shouldn't need to bother with - most of the time. Especially for such a simple problem.I also don't fully understand your need for the null reducer solution.
What is the problem your trying to solve?
In my head the situation looks like this:
Given the user is logged in an the state is something like
state = { user: { name: 'mat' } }redux-storageNow the user logs out and a
USER_LOGOUTaction is dispatchedSomeone (
UserReducer!?) is triggered by theUSER_LOGOUTaction and modifies the statestate = { user: null }The changed state will be detected by
redux-storageand written to the engineDone
And this behaviour sounds pretty sane to me 😄
In @mattkrick's case, we are using
store.replaceReducer()to dynamically load different reducers between routes. We're building a fairly complex app.When we hit our logout route, it won't be clear what information we want to expunge from the store...but, we want to get it all. We're trying to avoid leaving one user's private information in localStorage and having it available to another if they switch accounts when using the same web browser.
@mattkrick: I think
store.replaceReducer(...)with reducer that's built from a whitelist is probably the way to go. I think @michaelcontento's point ofredux-storageis just a mirror (roughly paraphrasing) makes sense...that definitely works for 1 reducer that you own, but for fun let's say you have 8 reducers: some you own, some are 3rd party, some are loaded initially, some are asynchronously added via webpack magic + replaceReducer.
For example, you have a reduxForm reducer & you persist some form data. If their browser crashes, you are a rockstar because the boot back up to a their form half filled out. That's awesome! But if they click log out, you should probably clear their half-finished form because it has sensitive info & they're at a public computer.
It's not enough to just null out the reducer (
state.reduxForm = undefined), rather you'll need todelete state.reduxFormsince your initial reducer doesn't know about it.@jordanh whoa same time! yeah, let's just null out the entire thing, & then replace the nullReducer with an initialReducer so it's the same as a refresh.
Well there is always the
engine.save({})sledgehammer 😉^^^^ _that!_ ^^^^
let's go with that. sledgehammers get stuff done!
Note that this would only solve a potential information leak through
redux-storage. And ONLY up until a new action triggers a newengine.save!This is important to remember:
redux-storageis the "persistence layer behindredux". So if your unable to fully clear/reset the state within redux there is still a possible information leak. And those informations might also be stored throughredux-storageat any time in the future.Only
engine.save({})with a immediate full redux-stack reload (possible by a browser refresh) would solve the information leak on all layers.Ha. We're having this same conversation on our internal Slack right now!
Did you find a final solution you're happy with? If so, would it be possible to share it with us? 😄
Oh, and please close this issue if there is nothing
redux-storagecan do for you 👼yep, all good over here. Thanks for putting up with me while we found a good pattern!
(deleted our original solution, posting a new one)
Originally we were going to replace our dynamically loaded reducers but in the end went with a much simpler, much more redux-y solution.
After reading this Stackoverflow answer, we ended up wrapping our combined reducers in a new rootReducer that can reset application state.
Now we we log out, we simply dispatch the reset action and let
redux-storageact as a mirror.Details are in this PR from our repository.