微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 firebase 中验证电子邮件时遇到问题,applyActionCode 一直说我的代码无效

如何解决在 firebase 中验证电子邮件时遇到问题,applyActionCode 一直说我的代码无效

我一直在尝试使用 firebase 验证电子邮件,但由于某种原因,emailVerified 字段从未变为真。我成功收到电子邮件链接,当我打开链接时,它会将我重定向回验证电子邮件页面,在页面上我解析 url 并捕获 oob 代码,然后传递给 applyActionCode 函数。当我这样做时,它一直告诉我我的代码无效。请帮忙..

我发送电子邮件验证的注册功能(这部分有效)

 const handleSignup = async (email,password) => {
    try {
      setLoading(true);
      await signup(email,password).then(() => {
        sendVerificationEmail(email);
      });
      // history.push('/home');
    } catch (err) {
      // firebase error
      handleInputValidation(err);
      setLoading(false);
    }
  };

VerifyEmail.jsx(这是我打开链接重定向到的页面

const EmailVerification = () => {

  const {
    currentUser,isCorrectEmailLink,signInWithEmail,sendVerificationEmail,verifyWithCode,updateUserForVerification,} = useAuth();
  const currentUserEmail = currentUser.email;

  const query = window?.location?.href?.split('oobCode=')[1];
  const oob = query?.split('&mode')[0];
  console.log(oob,'here');

  const verifyEmail = async (emailLink,email) => {
    const isCorrect = isCorrectEmailLink(emailLink);

    if (oob !== undefined) {
      verifyWithCode(oob);
    }
    await updateUserForVerification();
  };

  useEffect(() => {
    if (!currentUser.isverified) {
      verifyEmail(window.location.href);
    }
  },[]);

  return (
    <GridContainer>
      <LoginContainer>
        <WelcometoDavie />
        <AppletContainer>
          <WelcomeText>Verify Your email adress</WelcomeText>
          <Applet>
            <FormName>Verify</FormName>
            <LoginTextFieldContainer>
              Verification code sent
              <button onClick={() => sendVerificationEmail(currentUserEmail)} type="button">
                send email
              </button>
            </LoginTextFieldContainer>
          </Applet>
        </AppletContainer>
      </LoginContainer>
    </GridContainer>
  );
};

export default EmailVerification;

这是我在发送从电子邮件链接 url

enter image description here

获取的 oob 代码时遇到的错误Based on this answer

请帮我解决这个问题,这个问题已经有几个星期了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。