<commit_before>// @flow
import axios from 'axios';
import gitAuth from '../utils/github.settings';

export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
export const LOGIN_FAILURE = 'LOGIN_FAILURE';
export const LOGOUT = 'LOGOUT';

type authInfoType = {
  client_id: string,
  client_secret: string,
  code: string
};


const postCredentials = (authInfo: authInfoType) => {
  const url = 'https://github.com/login/oauth/access_token';
  const config = {
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
      'Cache-Control': 'no-cache'
    }
  };
  return axios.post(url, authInfo, config);
};

export const teacherLogin = (authCode: string) => (dispatch: *) => {
  const authInfo = {
    client_id: gitAuth.client_id,
    client_secret: gitAuth.client_secret,
    code: authCode
  };

  return postCredentials(authInfo)
    .then(response => {
      if (response.data.access_token) {
        return dispatch({ type: LOGIN_SUCCESS, token: response.data.access_token });
      }
      return dispatch({ type: LOGIN_FAILURE, error: response.data });
    })
    .catch(error => {
      console.error(error);
      dispatch({ type: LOGIN_FAILURE, error });
    });
};

export const logout = () => ({ type: LOGOUT });
<commit_msg>access token placed on localstorage AND state upon retrieval from github<commit_after>// @flow
import axios from 'axios';
import gitAuth from '../utils/github.settings';

export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
export const LOGIN_FAILURE = 'LOGIN_FAILURE';
export const LOGOUT = 'LOGOUT';

type authInfoType = {
  client_id: string,
  client_secret: string,
  code: string
};


const postCredentials = (authInfo: authInfoType) => {
  const url = 'https://github.com/login/oauth/access_token';
  const config = {
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
      'Cache-Control': 'no-cache'
    }
  };
  return axios.post(url, authInfo, config);
};

export const teacherLogin = (authCode: string) => (dispatch: *) => {
  const authInfo = {
    client_id: gitAuth.client_id,
    client_secret: gitAuth.client_secret,
    code: authCode
  };

  return postCredentials(authInfo)
    .then(response => {
      if (response.data.access_token) {
        localStorage.setItem('token', response.data.access_token);
        return dispatch({ type: LOGIN_SUCCESS, token: response.data.access_token });
      }
      return dispatch({ type: LOGIN_FAILURE, error: response.data });
    })
    .catch(error => {
      console.error(error);
      dispatch({ type: LOGIN_FAILURE, error });
    });
};

export const logout = () => ({ type: LOGOUT });

{'fraction_non_alphanumeric': 0.1401057401812689, 'fraction_numerical': 0.0, 'mean_word_length': 3.5204778156996586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '1653620', 'n_tokens_mistral': 824, 'n_tokens_neox': 829, 'n_words': 196}