{"size": 1011, "ext": "js", "max_stars_repo_path": "app/client/reducers/authenticatedUser.js", "max_stars_repo_name": "mazma1/postit-devops", "max_stars_repo_stars_event_min_datetime": "2017-11-10T02:20:38.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-10T02:20:38.000Z", "max_issues_repo_path": "app/client/reducers/authenticatedUser.js", "max_issues_repo_name": "mazma1/post-it", "max_issues_repo_issues_event_min_datetime": "2017-06-14T08:14:23.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-25T20:09:46.000Z", "max_forks_repo_path": "app/client/reducers/authenticatedUser.js", "max_forks_repo_name": "mazma1/postit-devops", "max_forks_repo_forks_event_min_datetime": "2017-08-02T21:59:20.000Z", "max_forks_repo_forks_event_max_datetime": "2017-08-02T21:59:20.000Z"}
{"max_stars_count": 1, "max_issues_count": 29, "max_forks_count": 1, "avg_line_length": 25.275, "max_line_length": 73, "alphanum_fraction": 0.6261127596}
import isEmpty from 'lodash/isEmpty';
import { SET_CURRENT_USER, DELETE_CURRENT_USER } from '../actions/types';
import initialState from '../utils/initialState';


/**
* Reducer for authentication-related actions
*
* @param {object} state - The old state of the application
* @param {object} action - The dispatched action
*
* @returns {object} - The new application state
*/
export default (state = initialState.auth, action = {}) => {
  switch (action.type) {
    case SET_CURRENT_USER:
      return {
        ...state,
        isAuthenticated: !isEmpty(action.user),
        user: {
          id: action.user.data.id,
          firstname: action.user.data.firstName,
          lastname: action.user.data.lastName,
          username: action.user.data.username,
          email: action.user.data.email
        }
      };

    case DELETE_CURRENT_USER:
      return {
        ...state,
        isAuthenticated: !isEmpty(action.user),
        user: action.user
      };

    default:
      return state;
  }
};
