我的注销用户功能似乎根本不起作用。我从登录时的警报中调用它,但它似乎没有调用它。如果我尝试在末尾添加“()”,它只会给我一个错误。
loginUser = (email, password) => {
try {
firebase.auth().signInWithEmailAndPassword(email, password).then(function (user){
console.log(user)
console.log('we are logged in boys')
Alert.alert(
'Signed In',
'You have signed in. Well done!',
[
{text: 'Sign Out', onPress: () => this.signOutUser},
],
{ cancelable: false }
)
})
}
catch(error) {
console.log(error.toString())
}
}
signOutUser = () => {
console.log('Do we reach this or not')
firebase.auth().signOut().then(function (user){
// Sign-out successful.
console.log('We are signing out!')
}).catch(function(error) {
// An error happened.
console.log('There is an issue!')
});
}
最佳答案
this
里面signInWithEmailAndPassword
回调不是您所期望的。将回调函数更改为 arrow function ,比如
firebase.auth().signInWithEmailAndPassword(email, password).then((user) => {
...
});
另外,将 onPress 函数的分配更改为
{text: 'Sign Out', onPress: this.signOutUser}
希望这会有所帮助!
关于javascript - React Native - Alert.alert 似乎没有调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52249453/