I've created a small application that permits a user to login and logout using ngrx state. The user login works well. I can login and using an AuthGuard I can check if the user is still login in the app after the refresh of the page. Now I should logout the user. This is my action:
export const LOGOUT = '[Auth] Logout';
export const logout = createAction(
LOGOUT
);
than the effect
logout$ = createEffect(() =>
this.actions$
.pipe(
ofType(userActions.logout),
tap(action => {
localStorage.removeItem('user');
this.router.navigate(['login']);
})
)
,{dispatch: false});
and of ourse the reducer:
export const authReducer = createReducer (
defaultUser,
on(userActions.logout, (state, action) => {
return {
user: undefined
}
})
)
After that, I can create in my component a logout button with this
onLogout(){
this.store.dispatch(logout())
}
I expect that the dispatch call the action and then the effect. Inside the effect it should remove the user from the localStorage. but even if I try to debug the effect it doesn't enter inside the tap operator. It doesn't remove the item and it doesn't redirect to login. Is there anything else i missed here?