import * as auth from './../actions/auth.actions' ; export interface AuthState { loggedIn : boolean ; errorMsg : string ; } export const initialState = { loggedIn : false , errorMsg : null } ; export function authReducer ( state = initialState , action ) { switch ( action . type ) { case auth . LOGIN : return { ... state , user : action . payload } ; case auth . LOGIN_SUCCESS : return { ... state , loggedIn : true , tokenInfo : action . payload } ; case auth . TOKEN_EXPIRE : return { ... state , tokenInfo : action . payload } ; case auth . LOGIN_FAIL : return { ... state , errorMsg : 'Invalid user credential' } ; case auth . LOGOUT : case auth . REDIRECT : return { ... state , loggedIn : false , tokenInfo : null } ; default : return state ; } } export const getLoginState = ( state ) => state . loggedIn ; export const getLoginStatus = ( state ) => state . errorMsg ;