单击确认电子邮件后,Firebase emailVerified变量不会更改

时间:2020-05-14 17:00:35

标签: javascript reactjs firebase firebase-authentication email-verification

我将Firebase与ReactJS一起使用,创建用户后,我将发送确认电子邮件,单击链接后,无论我尝试什么,变量emailVerified都保持为false。

以下是我创建用户并发送电子邮件的代码:

const createUserWithEmailAndPasswordHandler = async (event, email, password) => {
event.preventDefault();
try{
  const {user} = await auth.createUserWithEmailAndPassword(email, password);
  user.sendEmailVerification().then(function() {
    user.reload()
  }).catch(function(error) {
    console.log(error);
  });
generateUserDocument(user, {displayName});

}
catch(error){
  setError('Error Signing up with email and password');
}
}

这是generateDocument代码:

export const generateUserDocument = async (user, additionalData) => {


if (!user) return;

  const userRef = firestore.doc(`users/${user.uid}`);
  const snapshot = await userRef.get();

  if (!snapshot.exists) {
    const { email,emailVerified, displayName, photoURL } = user;
    try {
      await userRef.set({
        displayName,
        email,
        emailVerified,
        photoURL,
        ...additionalData
      });
    } catch (error) {
      console.error("Error creating user document", error);
    }
  }
  return getUserDocument(user.uid);
};

即使我注销并登录后,刷新页面,它仍然不会变为true。

感谢您的帮助!

0 个答案:

没有答案
相关问题