import * as types from '../actions/types';

const initialState = {
  user: null,
  isLoggedIn: false
};

export default (state = initialState, action) => {
  switch (action.type) {
    case types.AUTH_LOGIN_SUCCESS:
      return {
        ...state,
        user: action.user,
        isLoggedIn: true
      };
    case types.AUTH_LOGIN_ERROR:
    case types.AUTH_LOGOUT_SUCCESS:
      return initialState;
    default:
      return state;
  }
};
