<commit_before>import {
  LOGIN_USER_REQUEST, LOGIN_USER_SUCCESS, LOGIN_USER_FAILURE,
  AUTH_USER_REQUEST, AUTH_USER_SUCCESS, AUTH_USER_FAILURE,
  LOGOUT_USER_REQUEST
} from '../constants/ActionTypes'

const initialState = {
  user: null,
  isAuthenticated: false,
  isAuthenticating: false,
  error: null,
  token: null
}

export default function Auth(state = initialState, action) {
  switch (action.type) {
    case AUTH_USER_REQUEST:
      return {
        ...state,
        user: null,
        isAuthenticating: true,
        error: null
      }

    case AUTH_USER_SUCCESS:
      const auth = action.response.entities.auth[action.response.result];
      if(auth.token){
        localStorage.setItem('token', auth.token);
      }

      return {
        ...state,
        user: auth.user,
        isAuthenticated: true,
        isAuthenticating: false,
        error: null
      }

    case AUTH_USER_FAILURE:
      return {
        ...state,
        user: null,
        isAuthenticated: false,
        isAuthenticating: false,
        error: action.error
      }

    case LOGOUT_USER_REQUEST:
      localStorage.removeItem('token');
      return {
        ...initialState
      }
    default:
      return state
  }
}<commit_msg>Remove authed state on logout success<commit_after>import {
  LOGIN_USER_REQUEST, LOGIN_USER_SUCCESS, LOGIN_USER_FAILURE,
  AUTH_USER_REQUEST, AUTH_USER_SUCCESS, AUTH_USER_FAILURE,
  LOGOUT_USER_REQUEST, LOGOUT_USER_SUCCESS
} from '../constants/ActionTypes'

const initialState = {
  user: null,
  isAuthenticated: false,
  isAuthenticating: false,
  error: null,
  token: null
}

export default function Auth(state = initialState, action) {
  switch (action.type) {
    case AUTH_USER_REQUEST:
      return {
        ...state,
        user: null,
        isAuthenticating: true,
        error: null
      }

    case AUTH_USER_SUCCESS:
      const auth = action.response.entities.auth[action.response.result];
      if(auth.token){
        localStorage.setItem('token', auth.token);
      }

      return {
        ...state,
        user: auth.user,
        isAuthenticated: true,
        isAuthenticating: false,
        error: null
      }

    case AUTH_USER_FAILURE:
      return {
        ...state,
        user: null,
        isAuthenticated: false,
        isAuthenticating: false,
        error: action.error
      }
/*
    case LOGOUT_USER_REQUEST:
      return {
        ...initialState
      }*/

    case LOGOUT_USER_SUCCESS:
      localStorage.removeItem('token');
      return {
        ...initialState
      }
    default:
      return state
  }
}
{'fraction_non_alphanumeric': 0.09426702577914582, 'fraction_numerical': 0.0, 'mean_word_length': 2.262233375156838, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1638767', 'n_tokens_mistral': 792, 'n_tokens_neox': 792, 'n_words': 166}