<commit_before>import axios from 'axios'
import _ from 'lodash'
import config from '../config'

// really important for using with passport.js
// https://stackoverflow.com/questions/40941118/axios-wont-send-cookie-ajax-xhrfields-does-just-fine
axios.defaults.withCredentials = true

let user = {
  authenticated: false
}

// let jwtToken = null

export default {

  user: user,
  // jwtToken: jwtToken,

  login (newUser) {
    console.log('>> auth.login', newUser)
    return axios
      .post(config.apiUrl + '/api/login', newUser)
      .then(
        (res) => {
          if (res.data.success) {
            localStorage.setItem('user', JSON.stringify(newUser))
            // localStorage.setItem('jwtToken', res.data.jwtToken)
            // jwtToken = res.data.jwtToken
            user.authenticated = true
            _.assign(user, res.data.user)
            console.log('>> auth.login data', res.data)
          }
          return res
        })
  },

  register (newUser) {
    console.log('>> auth.register', newUser)
    return axios.post(config.apiUrl + '/api/register', newUser)
  },

  update (editUser) {
    console.log('>> auth.update', editUser)
    return axios.post(config.apiUrl + '/api/update', editUser)
  },

  restoreLastUser () {
    let lastUser = JSON.parse(localStorage.getItem('user'))
    // let jwtToken = localStorage.getItem('jwtToken')
    console.log('>> auth.restoreLastUser', lastUser)
    return this.login(lastUser)
  },<commit_msg>update user properly<commit_after>import axios from 'axios'
import _ from 'lodash'
import config from '../config'

// really important for using with passport.js
// https://stackoverflow.com/questions/40941118/axios-wont-send-cookie-ajax-xhrfields-does-just-fine
axios.defaults.withCredentials = true

let user = {
  authenticated: false
}

// let jwtToken = null

export default {

  user: user,
  // jwtToken: jwtToken,

  login (newUser) {
    console.log('>> auth.login', newUser)
    return axios
      .post(config.apiUrl + '/api/login', newUser)
      .then((res) => {
        if (res.data.success) {
          localStorage.setItem('user', JSON.stringify(newUser))
          // localStorage.setItem('jwtToken', res.data.jwtToken)
          // jwtToken = res.data.jwtToken
          user.authenticated = true
          _.assign(user, res.data.user)
          console.log('>> auth.login data', res.data)
        }
        return res
      })
  },

  register (newUser) {
    console.log('>> auth.register', newUser)
    return axios.post(config.apiUrl + '/api/register', newUser)
  },

  update (editUser) {
    console.log('>> auth.update', editUser)
    return axios.post(config.apiUrl + '/api/update', editUser)
      .then(res => {
        if (res.data.success) {
          _.assign(user, editUser)
          localStorage.setItem('user', JSON.stringify(user))
        }
      })
  },

  restoreLastUser () {
    let lastUser = JSON.parse(localStorage.getItem('user'))
    // let jwtToken = localStorage.getItem('jwtToken')
    console.log('>> auth.restoreLastUser', lastUser)
    return this.login(lastUser)
  },
{'fraction_non_alphanumeric': 0.14534883720930233, 'fraction_numerical': 0.00516795865633075, 'mean_word_length': 2.660756501182033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '5404428', 'n_tokens_mistral': 1013, 'n_tokens_neox': 988, 'n_words': 194}