<commit_before>import axios from 'axios';
import * as ACTIONS from './constants';

function requestSignup(creds) {
  return {
    type: ACTIONS.SIGNUP_REQUEST,
    isFetching: true,
    isAuthenticated: false,
    creds
  };
}

function recieveSignup(user) {
  localStorage.setItem('id_token', user.data.id_token);
  return {
    type: ACTIONS.SIGNUP_SUCCESS,
    isFetching: false,
    isAuthenticated: true,
    id_token: user.data.id_token
  };
}


function signupError(message) {
  return {
    type: ACTIONS.SIGNUP_FAILURE,
    isFetching: false,
    isAuthenticated: false,
    message
  };
}

export function signupUser(creds, dispatch) {
  return () => {
    dispatch(requestSignup(creds));
    return axios.post('api/signup', creds)
      .then(res => dispatch(recieveSignup(res)))
      .catch(err => dispatch(signupError(err)));
  };
}

function requestLogin(creds) {
  return {
    type: ACTIONS.LOGIN_REQUEST,
    isFetching: true,
    isAuthenticated: false,
    creds
  };
}

function recieveLogin(user) {
  localStorage.setItem('id_token', user.data.id_token);
  return {
    type: ACTIONS.LOGIN_SUCCESS,
    isFetching: false,
    isAuthenticated: true,
    id_token: user.data.id_token
  };
}


function loginError(message) {
  return {
    type: ACTIONS.LOGIN_FAILURE,
    isFetching: false,
    isAuthenticated: false,
    message
  };
}

export function loginUser(creds, dispatch) {
  return () => {
    dispatch(requestLogin(creds));
    return axios.post('api/login', creds)
      .then(res => dispatch(recieveLogin(res)))
      .catch(err => dispatch(loginError(err)));
  };
}
<commit_msg>add function to create token in local storage, close #37<commit_after>import axios from 'axios';
import * as ACTIONS from './constants';

function saveToLocalStorage(token) {
  localStorage.setItem('id_token', token);
}

function requestSignup(creds) {
  return {
    type: ACTIONS.SIGNUP_REQUEST,
    isFetching: true,
    isAuthenticated: false,
    creds
  };
}

function recieveSignup(user) {
  saveToLocalStorage(user.data.id_token);
  return {
    type: ACTIONS.SIGNUP_SUCCESS,
    isFetching: false,
    isAuthenticated: true,
    id_token: user.data.id_token
  };
}


function signupError(message) {
  return {
    type: ACTIONS.SIGNUP_FAILURE,
    isFetching: false,
    isAuthenticated: false,
    message
  };
}

export function signupUser(creds, dispatch) {
  return () => {
    dispatch(requestSignup(creds));
    return axios.post('api/signup', creds)
      .then(res => dispatch(recieveSignup(res)))
      .catch(err => dispatch(signupError(err)));
  };
}

function requestLogin(creds) {
  return {
    type: ACTIONS.LOGIN_REQUEST,
    isFetching: true,
    isAuthenticated: false,
    creds
  };
}

function recieveLogin(user) {
  saveToLocalStorage(user.data.id_token);
  return {
    type: ACTIONS.LOGIN_SUCCESS,
    isFetching: false,
    isAuthenticated: true,
    id_token: user.data.id_token
  };
}


function loginError(message) {
  return {
    type: ACTIONS.LOGIN_FAILURE,
    isFetching: false,
    isAuthenticated: false,
    message
  };
}

export function loginUser(creds, dispatch) {
  return () => {
    dispatch(requestLogin(creds));
    return axios.post('api/login', creds)
      .then(res => dispatch(recieveLogin(res)))
      .catch(err => dispatch(loginError(err)));
  };
}

{'fraction_non_alphanumeric': 0.12545126353790614, 'fraction_numerical': 0.0006016847172081829, 'mean_word_length': 3.643854748603352, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6233701', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1166, 'n_words': 213}