I am developing a react native app with firebase authentication. But when I login successfully the the navigation showing some problem, like, Undefined is not an object(evaluating 'this.props.navigation'). but the same cone used for navigation working properly on other pages. I Tried a lot of things, but nothing works Guys please help me.
import React from "react";
import {
Text,
View,
Image,
TouchableOpacity,
AsyncStorage,
TextInput
} from "react-native";
import { styles } from "./Css";
import { KeyboardAvoidingView } from "react-native";
import { RkTextInput, RkButton } from "react-native-ui-kitten";
import { Actions } from "react-native-router-flux";
import { Icon } from "react-native-elements";
import * as firebase from "firebase";
export default class Login extends React.Component {
constructor(props) {
super(props);
this.state = {
email: "",
password: "",
userId: "",
errorMessage: null,
};
}
componentDidMount() {
this._loadInitialState().done();
}
_loadInitialState = async () => {
var value = await AsyncStorage.getItem("user");
if (value !== null) {
this.props.navigation.navigate("NewHome")
}
};
handleLogin = (email, password) => {
if(this.state.email.length<1){
alert("Enter an Email");
return;
}
if (this.state.email.includes("@")==false){
alert("Use an email as Username");
return;
}
if(this.state.password.length<6){
alert("please enter correct password")
return;
}
//alert(firebase.auth().currentUser.uid)
firebase.auth().signInWithEmailAndPassword(email, password).then(function(user){
if(user){
this.props.navigation.navigate("NewHome"), //problem
//--------------------------Async Test--------------------------
AsyncStorage.setItem("user", firebase.auth().currentUser.uid)
//--------------------------------------------------------------
}else{
}
}
)
.catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === "auth/wrong-password") {
alert("Wrong password.");
return;
} else {
alert(errorMessage);
return;
}
console.log(error);
});
};