【问题标题】:Check if user completed email verification ReactJS Firebase检查用户是否完成了电子邮件验证 ReactJS Firebase
【发布时间】:2021-04-11 16:41:11
【问题描述】:

我有以下代码可以帮助注册用户。目前正在尝试集成电子邮件验证并在完成后执行 updateProfile 回调。我可以使用 .sendEmailVerification() 方法发送电子邮件,但不知道如何进行检查和执行其他代码。非常感谢您对此的任何帮助!

export default function SignUp() {
  const history = useHistory();
  const { firebase } = useContext(FirebaseContext);

  const [firstName, setFirstName] = useState('');
  const [emailAddress, setEmailAddress] = useState('');
  const [password, setPassword] = useState('');
  const [error, setError] = useState('');

  const isInvalid = firstName === '' || password === '' || emailAddress === '';

  const handleSignup = (event) => {
    event.preventDefault();

    return firebase
      .auth()
      .createUserWithEmailAndPassword(emailAddress, password)
      .then((result) =>
        result.user
          //.sendEmailVerification()
          .updateProfile({
            displayName: firstName,
            photoURL: Math.floor(Math.random() * 5) + 1,
          })
          .then(() => {
            history.push(ROUTES.BROWSE);
          })
      )
      .catch((error) => {
        setFirstName('');
        setEmailAddress('');
        setPassword('');
        setError(error.message);
      });
  };

【问题讨论】:

    标签: reactjs firebase firebase-authentication email-verification


    【解决方案1】:

    没必要想太多。创建帐户 (createUserWithEmailAndPassword) 时,在 firebase 对象中创建另一个密钥,将用户标记为未验证状态

    {
        email: '',
        password: '',
        verified: false
    }
    

    用户点击验证URL成功后,标记为真。

    {
        email: '',
        password: '',
        verified: true
    }
    

    【讨论】:

      【解决方案2】:

      用户已经有一个属性来处理这个问题。

      https://firebase.google.com/docs/reference/js/firebase.User#emailverified

      【讨论】:

        猜你喜欢
        • 2020-11-13
        • 1970-01-01
        • 2021-03-13
        • 2020-07-14
        • 2021-05-17
        • 1970-01-01
        • 1970-01-01
        • 2019-09-04
        • 1970-01-01
        相关资源
        最近更新 更多