我正在使用“反应导航”中的“ createStackNavigator”,如果我能够登录到Firebase,则想将navigation.push('Details')导入我的函数。我只会收到一个错误。
loginUser = (email,password) => {
try{
firebase.auth().signInWithEmailAndPassword(email, password).then(function(user){
this.props.navigation.push('Details')
})
}
catch(error){
console.log(error.toString())
}
}
这是我的根堆栈:
const RootStack = createStackNavigator(
{
Home: {
screen: HomeScreen, navigationOptions: { header: null },
},
Details: {
screen: DetailsScreen, navigationOptions: { header: null },
},
},
{
initialRouteName: 'Home',
}
);
我也在尝试进行设置,以便如果用户登录,它将自动转到DetailsScreen。我可以这样做吗?:
componentDidMount(){
firebase.auth().onAuthStateChanged((user) => {
if(user != null) {
console.log(user)
console.log("User is logged in!")
}
})
}