【发布时间】:2017-12-02 06:59:38
【问题描述】:
我正在开发一个 React Native 项目并使用 Firebase。
我正试图让用户在验证其电子邮件地址后登录。我向用户发送了一封注册电子邮件,用户单击验证链接以验证自己,然后应该能够登录。我当前的代码允许用户登录后验证,但只有在我刷新应用程序之后。我希望用户在验证后登录而不刷新应用程序。 我发现我可以在 Firebase 中使用 getIdToken() 来实现它。但不知何故,我似乎无法让它工作。任何指示我在哪里做错了什么?提前致谢。
我的这个函数的代码 sn-p 是:
_login = () =>{
var me = this;
firebaseRef.auth().onAuthStateChanged(function(user) {
if(user){
user.getIdToken(forceRefresh).then(function() {
if( firebaseRef.auth().currentUser.emailVerified){
firebaseRef.auth().signInWithEmailAndPassword(this.state.email, this.state.password).then(function(){
// some function here, which is working perfectly
},
function(error) {
alert('The username or password is incorrect');
console.log(error);
})
}
else {
alert('Your email has not been verified');
}
},
function(error) {
alert('There is an email verification error');
console.log(error);
})
}
}
)
}
【问题讨论】:
标签: firebase react-native firebase-authentication