Commit 4d181631 by Tonk

update register and login

parent e9ada991
......@@ -45,20 +45,24 @@ class AuthLoadingScreen extends Component {
// Preload data from an external API && Preload data using AsyncStorage
const alreadyLaunched = await AsyncStorage.getItem('alreadyLaunched');
const RememberedLogin = await AsyncStorage.getItem('RememberedLogin');
// console.log('alreadyLaunched', alreadyLaunched);
// console.log('RememberedLogin', RememberedLogin);
app.auth().onAuthStateChanged(async user => {
if (user) {
console.log(user);
await this.props.getCurrentUser(user);
await this.getToken();
this.props.navigation.navigate(RememberedLogin === 'true' ? 'Main' : 'Login');
// createMockData();
if (alreadyLaunched === 'true') {
if (RememberedLogin === 'true') {
app.auth().onAuthStateChanged(async user => {
if (user) {
console.log(user);
await this.props.getCurrentUser(user);
await this.getToken();
this.props.navigation.navigate('Main');
}
});
} else {
this.props.navigation.navigate(alreadyLaunched === 'true' ? 'Login' : 'Onboarding');
app.auth().signOut();
this.props.navigation.navigate('Login');
}
});
} else {
this.props.navigation.navigate('Onboarding');
}
} catch (e) {
alert(e);
}
......
......@@ -5,8 +5,10 @@ import AsyncStorage from '@react-native-community/async-storage';
import LoginForm from '../../components/Form/LoginForm';
import { KeyboardAvoidingView, View } from 'react-native';
import app from '../../firebase';
import { getCurrentUser } from '../../reduxStore/actions/cerrentUserAction';
import { connect } from 'react-redux';
export default class LoginScreen extends Component {
class LoginScreen extends Component {
static navigationOptions = {
header: null,
};
......@@ -22,6 +24,8 @@ export default class LoginScreen extends Component {
try {
const userCredential = await app.auth().signInWithEmailAndPassword(email, password);
if (userCredential) {
const user = app.auth().currentUser;
await this.props.getCurrentUser(user);
await AsyncStorage.setItem('alreadyLaunched', 'true');
if (this.state.isCheck === true) {
await AsyncStorage.setItem('RememberedLogin', 'true');
......@@ -74,3 +78,12 @@ export default class LoginScreen extends Component {
);
}
}
const mapDispatchToProps = {
getCurrentUser,
};
export default connect(
null,
mapDispatchToProps
)(LoginScreen);
import React, { Component } from 'react';
import { Container, Text, CheckBox, Icon } from 'native-base';
import { Text, CheckBox } from 'native-base';
import { color, theme } from '../../constants/Styles';
import { Platform, View, ScrollView } from 'react-native';
import { View, ScrollView } from 'react-native';
import RegisterForm from '../../components/Form/RegisterForm';
import { HeaderButtons, Item } from 'react-navigation-header-buttons';
import IoniconsHeaderButton from '../../components/IoniconsHeaderButton';
import app, { fireStore, baseURL } from '../../firebase';
import app from '../../firebase';
import { connect } from 'react-redux';
import { updateUser } from '../../reduxStore/actions/cerrentUserAction';
import { getCurrentUser, updateUser } from '../../reduxStore/actions/cerrentUserAction';
class RegisterScreen extends Component {
static navigationOptions = ({ navigation }) => ({
......@@ -43,15 +43,20 @@ class RegisterScreen extends Component {
createAccount = async values => {
const userData = { firstName: values.firstName, lastName: values.lastName, phoneNumber: values.phoneno };
try {
const reg = app.auth().createUserWithEmailAndPassword(values.email, values.password);
const reg = app
.auth()
.createUserWithEmailAndPassword(values.email, values.password)
.then(async value => {
await this.props.getCurrentUser(value);
await this.props.updateUser(userData);
});
if (reg) {
this.props.updateUser(userData); // can't update data when create user
app.auth().signOut();
this.props.navigation.navigate('Success');
}
} catch (error) {
console.log(error);
alert(error);
}
};
......@@ -84,13 +89,12 @@ class RegisterScreen extends Component {
}
}
const mapStateToProps = state => ({});
const mapDispatchToProps = {
updateUser,
getCurrentUser,
};
export default connect(
mapStateToProps,
null,
mapDispatchToProps
)(RegisterScreen);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment