diff --git a/src/app/shared/state/auth.reducer.ts b/src/app/shared/state/auth.reducer.ts index 95195a8..e999aef 100644 --- a/src/app/shared/state/auth.reducer.ts +++ b/src/app/shared/state/auth.reducer.ts @@ -1,3 +1,37 @@ import { UserModel } from "../models"; -import { createReducer, on } from "@ngrx/store"; +import { createReducer, on, Action } from "@ngrx/store"; import { AuthApiActions, AuthUserActions } from "src/app/auth/actions"; + +export interface State { + gettingStatus: boolean; + user: null | UserModel; + error: null | string; +} + +const initialState: State = { + gettingStatus: true, + user: null, + error: null +}; + +export const authReducer = createReducer( + initialState, + on(AuthUserActions.logout, (state, action) => { + return { + gettingStatus: false, + user: null, + error: null + }; + }), + on(AuthUserActions.login, (state, action) => { + return { + gettingStatus: true, + user: null, + error: null + }; + }) +); + +export function reducer(state: State | undefined, action: Action) { + return authReducer(state, action); +}