Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import firebase from 'firebase';
- import { LOGIN_USER_FAIL, EMAIL_CHANGED , PASSWORD_CHANGED , LOGIN_USER_SUCCESS, LOGIN_USER } from './types';
- import { Actions } from 'react-native-router-flux';
- //here define the actionCreator of email
- export const emailChanged = (text) => {
- return {
- //type of action defined in type.js file
- type: 'EMAIL_CHANGED',
- payload: text
- };
- };
- //here define the actionCreator of password
- export const passwordChanged = (text) => {
- return {
- //type of action defined in type.js file
- 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( () => {
- firebase.auth().createUserWithEmailAndPassword(email, password)
- .then(user => loginUserSuccess(dispatch, user) )
- .catch(() => loginUserFail(dispatch));
- });
- };
- };
- const loginUserFail = (dispatch) => {
- dispatch({type: LOGIN_USER_FAIL});
- Actions.main();
- };
- const loginUserSuccess = ( dispatch, user) => {
- dispatch({
- type: LOGIN_USER_SUCCESS,
- payload: user
- });
- };
Add Comment
Please, Sign In to add comment