function authReducer(
  state = { isLoaded: false, isEmpty: true },
  action
) {
  switch (action.type) {
    case LOGIN:
    case AUTH_UPDATE_SUCCESS:
      if (!action.auth) {
        return {
          isEmpty: true,
          isLoaded: true
        }
      }
      const auth = action.auth.toJSON ? action.auth.toJSON() : action.auth // eslint-disable-line no-case-declarations
      // Support keeping data
      if (action.preserve && action.preserve.auth) {
        return preserveValuesFromState(state, action.preserve.auth, {
          ...auth,
          isEmpty: false,
          isLoaded: true
        })
      }
      return { ...auth, isEmpty: false, isLoaded: true }
    case AUTH_LINK_SUCCESS:
    case AUTH_RELOAD_SUCCESS:
      if (!action.payload) {
        return {
          isEmpty: true,
          isLoaded: true
        }
      }
      return {
        ...(action.payload.toJSON ? action.payload.toJSON() : action.payload),
        isEmpty: false,
        isLoaded: true
      }
    case LOGIN_ERROR:
    case AUTH_EMPTY_CHANGE:
    case LOGOUT:
      // If it's reauthenticate keep user datas
      if (action.reauthenticate) {
        return preserveValuesFromState(state, true, {})
      }
      // Support keeping data when logging out
      if (action.preserve && action.preserve.auth) {
        return preserveValuesFromState(state, action.preserve.auth, {
          isLoaded: true,
          isEmpty: true
        })
      }
      return { isLoaded: true, isEmpty: true }
    default:
      return state
  }
}
Reducer for auth state. Changed by `LOGIN`, `LOGOUT`, and `LOGIN_ERROR` actions.
@param  {object} [state={isLoaded: false}] - Current auth redux state
@param  {object} action - Object containing the action that was dispatched
@param  {string} action.type - Type of action that was dispatched
@returns {object} Profile state after reduction