我的注销用户功能似乎根本不起作用。我在登录时从一个警报中调用它,但它似乎没有调用它。如果我试图在最后添加"()“,它只会给我一个错误。
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!')
});
}发布于 2018-09-10 14:47:04
signInWithEmailAndPassword内部的this回调不是您所期望的。将回调函数更改为arrow function,如下所示
firebase.auth().signInWithEmailAndPassword(email, password).then((user) => {
...
});另外,将assignment onPress函数更改为
{text: 'Sign Out', onPress: this.signOutUser}希望这能有所帮助!
发布于 2018-09-10 14:59:54
使用箭头函数更新您的函数:
loginUser = (email, password) => {
try {
firebase.auth().signInWithEmailAndPassword(email, password).then((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()},//Or Write this.signOutUser direct without arrow function
],
{ cancelable: false }
)
})
}
catch(error) {
console.log(error.toString())
}
}希望这能对你有所帮助。
发布于 2018-09-10 11:12:05
测试一下:
{text: 'Sign Out', onPress: () => { this.signOutUser(); } }https://stackoverflow.com/questions/52249453
复制相似问题