Javascript 如何检查firebase中的电子邮件是否在React Native中验证?
我与firebase的技能是基本的,我想得到的是,只有拥有已验证邮件的用户才能进入应用程序,如果没有显示未验证邮件的错误。这是我的代码:Javascript 如何检查firebase中的电子邮件是否在React Native中验证?,javascript,reactjs,firebase,react-native,firebase-authentication,Javascript,Reactjs,Firebase,React Native,Firebase Authentication,我与firebase的技能是基本的,我想得到的是,只有拥有已验证邮件的用户才能进入应用程序,如果没有显示未验证邮件的错误。这是我的代码: login (){ const user = firebase.auth().currentUser; const emailVerified = user.emailVerified; const validate = this.refs.formId.getValue(); if (validate &&
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”)来自示例下的通知,就像您使用
firebase.auth()的方式一样。currentUser
在:
注意:currentUser也可能为null,因为auth对象尚未设置
已完成初始化。如果您使用观察者跟踪
用户的登录状态,您不需要处理此情况
@bdroid,您不需要通过改革这个登录过程的流程来集成它们。我认为这也提供了一个正确的登录流程,首先使用Email和Password调用登录,在检测到用户是否经过验证后,决定在完成授权登录和未完成授权登录时分别执行哪些操作:
login (){
const validate = this.refs.formId.getValue();
firebase.auth().signInWithEmailAndPassword(validate.email, validate.password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/wrong-password') {
Toast.show({ text: 'Wrong password!', position: 'bottom', buttonText: 'Try Again' });
}
});
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
if (user.emailVerified === false) {
Toast.show({ text: 'Email Not Verified!', position: 'bottom', buttonText: 'Try Again' });
} else {
// successful login
}
} else {
// Toast.show({ text: 'Something Wrong!', position: 'bottom', buttonText: 'No user is signed in.' });
}
});
}
同样的情况?是的,但是我如何集成这两个功能呢?我是说auth和onchange?我测试了它,但是当我的用户登录时我仍然可以登录。电子邮件未验证我收到此错误:null不是一个对象(评估'validate.email)@bdroid问题似乎根本不在firebase.auth()
上,您没有一开始就正确获取表单中的值。@bdorid,但我想知道validate
为null时如何登录<代码>我对它进行了测试,但当我的密码被删除时,我仍然可以登录。电子邮件未验证
我有表单:输入忘记密码?