【发布时间】:2017-08-26 14:30:51
【问题描述】:
好吧,我已经尝试过使用多种方法来触发函数sendEmailVerification()。但没有一个工作成功。文档也没有帮助。
以下是我将使用的部分源代码。请让我知道如何纠正这个问题。
在我的控制台上,我收到以下错误:
btnSignUpWithGoogle.addEventListener('click', e => { var provider = new firebase.auth.GoogleAuthProvider(); firebase.auth().signInWithPopup(provider).then(function(result) { var token = result.credential.accessToken; 变种用户=结果.用户; }).catch(函数(错误){ var errorCode = error.code; var errorMessage = error.message; var email = error.email; var credential = error.credential; console.log(errorCode); }); }); btnLogin.addEventListener('click', e => { 常量电子邮件 = txtEmail.value; const pass = txtPassword.value; const auth = firebase.auth(); const promise = auth.signInWithEmailAndPassword(email, pass); promise.catch(e => console.log(e.message)); txtEmail.value = ""; txtPassword.value = ""; }); btnSignUp.addEventListener('click', e => { 常量电子邮件 = txtEmail.value; const pass = txtPassword.value; const auth = firebase.auth(); const promise = auth.createUserWithEmailAndPassword(email, pass); promise.catch(e => console.log(e.message)); txtEmail.value = ""; txtPassword.value = ""; 常量 emailVerified = firebaseUser.emailVerified; 如果(!emailVerified){ firebase.auth().firebaseUser.sendEmailVerification().then(function(){ alert('请检查您的电子邮件以验证您的帐户。'); }); } 别的 { alert('您的邮箱已通过验证!'); } }); firebase.auth().onAuthStateChanged(firebaseUser => { 如果(火力基地用户){ console.log(firebaseUser); console.log('登录!'); btnLogout.style.visibility = '可见'; } 如果(firebaseUser.emailVerified){ console.log('邮箱已验证'); } 别的 { console.log('邮箱未验证'); firebaseUser.sendEmailVerification(); } });TypeError:无法读取 null 的属性“emailVerified” 在 Object.firebase.auth.onAuthStateChanged.firebaseUser [下一个]
【问题讨论】:
-
if (firebaseUser.emailVerified) { 应该改为 if (firebaseUser && firebaseUser.emailVerified) {
标签: javascript authentication firebase firebase-authentication