Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/shared/state/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ActionReducerMap, createSelector, MetaReducer } from "@ngrx/store";
import * as fromAuth from "./auth.reducer";
import * as fromBooks from "./books.reducer";
import { logoutMetareducer } from "./logout.metareducer";

export interface State {
auth: fromAuth.State;
Expand All @@ -12,7 +13,7 @@ export const reducers: ActionReducerMap<State> = {
books: fromBooks.reducer
};

export const metaReducers: MetaReducer<State>[] = [];
export const metaReducers: MetaReducer<State>[] = [logoutMetareducer];

/**
* Auth Selectors
Expand Down
10 changes: 10 additions & 0 deletions src/app/shared/state/logout.metareducer.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
import { ActionReducer, Action } from "@ngrx/store";
import { AuthUserActions } from "src/app/auth/actions";

export function logoutMetareducer(reducer: ActionReducer<any>) {
return function(state: any, action: Action) {
if (action.type === AuthUserActions.logout.type) {
return reducer(undefined, action);
}

return reducer(state, action);
};
}