我与Firebase的技能是基本的,我想得到的是,只有谁拥有验证邮件的用户将能够进入应用程序,如果不显示尚未验证的电子邮件的错误.下面是我代码:
login (){
const user = firebase.auth().currentUser;
const emailVerified = user.emailVerified;
const validate = this.refs.formId.getValue();
if (validate && emailVerified != 'false') {
firebase.auth().signInWithEmailAndPassword(validate.email, validate.password)
.then(() => {
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
if (errorCode === 'auth/wrong-password') {
Toast.show({ text: 'Wrong password!', position: 'bottom', buttonText: 'Try Again' })
if (emailVerified === 'false') {
Toast.show({ text: 'Email Not Verified!', position: 'bottom', buttonText: 'Try Again' })
}else{
Toast.show({ text: 'Something Wrong!', position: 'bottom', buttonText: 'Try Again' })
}
});
}
}
我得到这个错误:null不是一个对象(正在评估'user.emailVerified)
1条答案
按热度按时间irtuqstp1#
从下面的例子中注意到,就像你在documentation中使用
firebase.auth().currentUser
的方式一样:注意:currentUser也可能为null,因为auth对象尚未完成初始化。如果使用观察者来跟踪用户的登录状态,则不需要处理这种情况。
@bdroid,你不需要整合它们,通过改革这个登录过程的流程。我想这也提供了一个合适的登录流程,先调用
signInWithEmailAndPassword
,检测用户是否通过验证后,分别决定完整授权登录和未完成授权登录的操作: