function auth (state = {
  isFetching: false,
  isAuthenticated: statusHtmlStorage('id_token') ? localStorage.getItem('id_token') : null,
  user: {
    isAdmin: statusHtmlStorage('isAdmin') ? localStorage.getItem('isAdmin') : null
  }
}, action) {
  switch (action.type) {
    case LOGIN_REQUEST:
      return Object.assign({}, state, {
        isFetching: true,
        isAuthenticated: false,
        user: action.creds
      })
    case LOGIN_SUCCESS:
      return Object.assign({}, state, {
        isFetching: false,
        isAuthenticated: true,
        errorMessage: '',
        isAdmin: action.user.isAdmin,
        user: action.user
      })
    case LOGIN_FAILURE:
      return Object.assign({}, state, {
        isFetching: false,
        isAuthenticated: false,
        errorMessage: action.message
      })
    case LOGOUT_SUCCESS:
      return Object.assign({}, state, {
        isFetching: true,
        isAuthenticated: false
      })
    case SIGN_UP_REQUEST:
      return Object.assign({}, state, {
        isFetching: true,
        isAuthenticated: false,
        user: action.creds
      })
    case SIGN_UP_SUCCESS:
      return Object.assign({}, state, {
        isFetching: false,
        isAuthenticated: true,
        errorMessage: '',
        user: action.user
      })
    case SIGN_UP_FAILURE:
      return Object.assign({}, state, {
        isFetching: false,
        isAuthenticated: false,
        errorMessage: action.message
      })
    default:
      return state
  }
}
// we would also want a util to check if the token is expired.
we would also want a util to check if the token is expired.
we would also want a util to check if the token is expired .
function auth (state = {
  isFetching: false,
  isAuthenticated: statusHtmlStorage('id_token') ? localStorage.getItem('id_token') : null,
  user: {
    isAdmin: statusHtmlStorage('isAdmin') ? localStorage.getItem('isAdmin') : null
  }
}, action) {
  switch (action.type) {
    case LOGIN_REQUEST:
      return Object.assign({}, state, {
        isFetching: true,
        isAuthenticated: false,
        user: action.creds
      })
    case LOGIN_SUCCESS:
      return Object.assign({}, state, {
        isFetching: false,
        isAuthenticated: true,
        errorMessage: '',
        isAdmin: action.user.isAdmin,
        user: action.user
      })
    case LOGIN_FAILURE:
      return Object.assign({}, state, {
        isFetching: false,
        isAuthenticated: false,
        errorMessage: action.message
      })
    case LOGOUT_SUCCESS:
      return Object.assign({}, state, {
        isFetching: true,
        isAuthenticated: false
      })
    case SIGN_UP_REQUEST:
      return Object.assign({}, state, {
        isFetching: true,
        isAuthenticated: false,
        user: action.creds
      })
    case SIGN_UP_SUCCESS:
      return Object.assign({}, state, {
        isFetching: false,
        isAuthenticated: true,
        errorMessage: '',
        user: action.user
      })
    case SIGN_UP_FAILURE:
      return Object.assign({}, state, {
        isFetching: false,
        isAuthenticated: false,
        errorMessage: action.message
      })
    default:
      return state
  }
}
function auth ( state = { isFetching : false , isAuthenticated : statusHtmlStorage ( 'id_token' ) ? localStorage . getItem ( 'id_token' ) : null , user : { isAdmin : statusHtmlStorage ( 'isAdmin' ) ? localStorage . getItem ( 'isAdmin' ) : null } } , action ) { switch ( action . type ) { case LOGIN_REQUEST : return Object . assign ( { } , state , { isFetching : true , isAuthenticated : false , user : action . creds } ) case LOGIN_SUCCESS : return Object . assign ( { } , state , { isFetching : false , isAuthenticated : true , errorMessage : '' , isAdmin : action . user . isAdmin , user : action . user } ) case LOGIN_FAILURE : return Object . assign ( { } , state , { isFetching : false , isAuthenticated : false , errorMessage : action . message } ) case LOGOUT_SUCCESS : return Object . assign ( { } , state , { isFetching : true , isAuthenticated : false } ) case SIGN_UP_REQUEST : return Object . assign ( { } , state , { isFetching : true , isAuthenticated : false , user : action . creds } ) case SIGN_UP_SUCCESS : return Object . assign ( { } , state , { isFetching : false , isAuthenticated : true , errorMessage : '' , user : action . user } ) case SIGN_UP_FAILURE : return Object . assign ( { } , state , { isFetching : false , isAuthenticated : false , errorMessage : action . message } ) default : return state } }
we would also want a util to check if the token is expired.
we would also want a util to check if the token is expired .