import firebase from 'firebase';
import {
  EMAIL_CHANGED,
  PASSWORD_CHANGED,
  LOGIN_USER_SUCCESS,
  LOGIN_USER_FAIL,
  LOGIN_USER
} from './types';

export const emailChanged = (text) => {
  return {
    type: EMAIL_CHANGED,
    payload: text
  };
};

export const passwordChanged = (text) => {
  return {
    type: PASSWORD_CHANGED,
    payload: text
  };
};

export const loginUser = ({ email, password }) => {
  return (dispatch) => {
    dispatch({ type: LOGIN_USER });

    firebase.auth().signInWithEmailAndPassword(email, password)
      .then(user => loginUserSuccess(dispatch, user))
      .catch((error) => {
        console.log(error);

        firebase.auth().createUserWithEmailAndPassword(email, password)
          .then(user => loginUserSuccess(dispatch, user))
          .catch(() => loginUserFail(dispatch));
      });
  };
};

const loginUserFail = (dispatch) => {
  dispatch({ type: LOGIN_USER_FAIL });
};

const loginUserSuccess = (dispatch, user) => {
  dispatch({
    type: LOGIN_USER_SUCCESS,
    payload: user
  });
};
@@ -30,32 +30,68 @@
 e';%0A
-im
+%0Aex
 port 
-%7B%0A  EMAIL_CHANGED
+const authTypes = %7B%0A  EMAIL_CHANGED: 'EMAIL_CHANGED'
 ,%0A  
@@ -102,24 +102,41 @@
 WORD_CHANGED
+: 'EMAIL_CHANGED'
 ,%0A  LOGIN_US
@@ -149,58 +149,98 @@
 CESS
-,%0A  LOGIN_USER_FAIL,%0A  LOGIN_USER%0A%7D from './types'
+: 'LOGIN_USER_SUCCESS',%0A  LOGIN_USER_FAIL: 'LOGIN_USER_FAIL',%0A  LOGIN_USER: 'LOGIN_USER'%0A%7D
 ;%0A%0Ae

Change authTypes