问题描述
我学习了ReactJs,现在我必须具有Firebase登录。我有一个设计问题,关于如何检测Firebase selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element
何时完成。用户按linkWithPopup
,我的匿名用户Firebase UID将被转换为Google凭据。
我必须检测该过程何时完成或中止。
这是我的代码:
linkWithPopup
我遇到的问题是,由于onSocialLoginLink = provider => {
const { firebase,changeUserRole } = this.props;
firebase.auth.currentUser
.linkWithPopup(firebase[provider])
// .linkWithRedirect(this.props.firebase[provider])
.then(changeUserRole())
.then(this.fetchSignInMethods)
.catch(error => this.setState({ error }));
};
当然是异步运行的,因此changeUserRole()
在linkWithPopup
返回之前被调用。这意味着即使用户选择中止登录,我的用户也可以从linkWithPopup
获得新的注册卷。
我必须检测该过程何时完成或中止。
推荐的最佳方法是什么? 我的想法是,如果我可以检测到登录窗口失去焦点并重新获得焦点时,可以查看Firebase用户是否已将提供者更改为Google还是仍然是匿名用户?这可行吗?
这是处理登录的changeUserRole()
:
Component
解决方法
如果这是问题,您可以添加一个条件来检查而不是更改角色
const { firebase,changeUserRole } = this.props;
firebase.auth.currentUser
.linkWithPopup(firebase[provider])
.then(res=>{
if(res.credential){changeUserRole()}
})
.then(this.fetchSignInMethods)
.catch(error => this.setState({ error }));
};```