On my react-redux app, I have the sign in actions that manage local storage for the token
export function signInUserSuccess(token) {
localStorage.setItem('token', token);
return {
type: SIGNIN_USER_SUCCESS,
payload: {
token: token
}
}
}
export function signOut() {
localStorage.removeItem('token');
return {
type: SIGNOUT_USER
}
}
and load any existing token from local storage at index.js
let token = localStorage.getItem('token');
if (token !== null) {
store.dispatch(signInUserSuccess(token));
}
I know this is not a good approach to have localStorage
at actions, and this answer suggests to handle it at middleware.
Having a look at one of the middleware, redux-storage, I do not understand how to replace the localStorage.setItem()
, localStorage.removeItem()
and localStorage.getItem()
with the given middleware operations which only uses LOAD
and SAVE
actions. I have no problem with setting up the package, but I do not understand how to use it for my sign in and sign out actions.