-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rehydrate state on logout #164
Comments
Exactly I have that requirement! |
Create a new meta-reducer that will reset reducer's state back to initial state. So when the user logs out, the application's reducer state will be reset to initial satate & the keys will also be preserved. Logout Reducer export function logoutMetareducer(reducer: ActionReducer<State>) {
return function (state: State, action: Action) {
if (action.type === AuthUserActions.logoutUser.type) {
return reducer(undefined, action);
}
return reducer(state, action);
};
} Action enum AuthUserActionTypes {
LOGOUT = '[Auth] User Logout'
}
const logoutUser = createAction(
AuthUserActionTypes.LOGOUT
); App State and Initial State configurations export interface State {
books: fromBooks.BooksState,
auth: fromAuth.UserState
}
const initialState: State = {
auth: {
user: null,
gettingStatus: false,
error: null
},
books: {
collection: [],
activeBookId: null
}
};
export const reducers: ActionReducerMap<State> = {
books: fromBooks.reducer,
auth: fromAuth.authReducer
};
export const metaReducers: MetaReducer<any, any>[] = [localStorageSyncReducer, logoutMetareducer]; |
Keys not preserved on logout. Here is example: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to reset store to its initial state on logout, but save localstorage keys.
Is there any solution to make it from the box?
My current solution is:
The text was updated successfully, but these errors were encountered: