<commit_before>import { FirebaseAPI, extractUserProperties } from 'shared/utils/firebaseUtils'
import { push } from 'react-router-redux'
import reactCookie from 'react-cookie';

import { AUTH_TOKEN } from 'shared/configs/auth';

export const AUTH_CREATE_USER = 'AUTH_CREATE_USER'
export const AUTH_LOGIN = 'AUTH_LOGIN'
export const AUTH_LOGOUT = 'AUTH_LOGOUT'

export function authLoad(user) {
  return (dispatch) => {
    dispatch(authLogIn(user.uid))
    dispatch(authLoadUser(user))
  }
}

export function authLoadUser(user) {
  return {
    type: AUTH_CREATE_USER, 
    user: user
  };
}

export function authLogIn(userUID) {
  return {
    type: AUTH_LOGIN, 
    userUID
  };
}

export function authLogOut() {
  return {
    type: AUTH_LOGOUT
  }
}

export function logIn() {
  return (dispatch) => {
    FirebaseAPI.signInWithPopup('facebook')
      .then((result) => {
        dispatch(createUser(result.user))
        firebase.database()
          .ref('/users/' + result.user.uid)
          .once('value')
          .then((snapshot) => {
            dispatch(authLoad(snapshot.val()))
          })
          .catch((error) => {
            console.log(error)
          })
        FirebaseAPI.getCurrentUserToken()
          .then(function(idToken) {
            reactCookie.save(AUTH_TOKEN, idToken, {
              maxAge: 60 * 60, // 1 hour
              // domain: '',
              // secure: true,
              // httpOnly: true
            });
          })
      }).catch(function(error) {
        console.log('signin failed', error)
      })
  };
}

export function createUser(user) {<commit_msg>use firebase from utils instead<commit_after>import { FirebaseAPI, extractUserProperties } from 'shared/utils/firebaseUtils'
import { push } from 'react-router-redux'
import reactCookie from 'react-cookie';

import { AUTH_TOKEN } from 'shared/configs/auth';

export const AUTH_CREATE_USER = 'AUTH_CREATE_USER'
export const AUTH_LOGIN = 'AUTH_LOGIN'
export const AUTH_LOGOUT = 'AUTH_LOGOUT'

export function authLoad(user) {
  return (dispatch) => {
    dispatch(authLogIn(user.uid))
    dispatch(authLoadUser(user))
  }
}

export function authLoadUser(user) {
  return {
    type: AUTH_CREATE_USER, 
    user: user
  };
}

export function authLogIn(userUID) {
  return {
    type: AUTH_LOGIN, 
    userUID
  };
}

export function authLogOut() {
  return {
    type: AUTH_LOGOUT
  }
}

export function logIn() {
  return (dispatch) => {
    FirebaseAPI.signInWithPopup('facebook')
      .then((result) => {
        dispatch(createUser(result.user))
        FirebaseAPI.get({ path: `/users/${result.user.uid}` })
          .then((snapshot) => {
            dispatch(authLoad(snapshot.val()))
          })
          .catch((error) => {
            console.log(error)
          })

        FirebaseAPI.getCurrentUserToken()
          .then(function(idToken) {
            reactCookie.save(AUTH_TOKEN, idToken, {
              maxAge: 60 * 60, // 1 hour
              // domain: '',
              // secure: true,
              // httpOnly: true
            });
          })
      }).catch(function(error) {
        console.log('signin failed', error)
      })
  };
}

export function createUser(user) {
{'fraction_non_alphanumeric': 0.12924322640921831, 'fraction_numerical': 0.003114294612270321, 'mean_word_length': 2.4279615795090717, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5922318', 'n_tokens_mistral': 992, 'n_tokens_neox': 989, 'n_words': 191}