繁体   English   中英

为什么 Firebase email 验证给我一个 http 400 错误?

[英]Why is Firebase email verification giving me a http 400 error?

我尝试在我的 React 网站中添加 email 验证,但似乎没有任何效果。 当我启动sendSignInLinkToEmail function 时,它返回此错误:

XHRPOSThttps://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=XXXXXXXXXXXXXXXXXXXX
[HTTP/3 400 Bad Request 455ms]
{
  "error": {
    "code": 400,
    "message": "INVALID_CONTINUE_URI : Missing domain in continue url",
    "errors": [
      {
        "message": "INVALID_CONTINUE_URI : Missing domain in continue url",
        "domain": "global",
        "reason": "invalid"
      }
    ]
  }
}

有问题的代码:

export const registerWithEmailAndPassword = async (name, email, password) => {
  try {
    await sendSignInLinkToEmail(auth, email, actionCodeSettings)
      .then(() => {
        // The link was successfully sent. Inform the user.
        // Save the email locally so you don't need to ask the user for it again
        // if they open the link on the same device.
        window.localStorage.setItem("emailForSignIn", email);
        console.log("test");
        // ...
      })
      .catch((error) => {
        const errorCode = error.code;
        const errorMessage = error.message;
        // ...
      });
      
    const res = await createUserWithEmailAndPassword(auth, email, password);
    const user = res.user;
    await addDoc(collection(db, "users"), {
      uid: user.uid,
      name,
      authProvider: "local",
      email,
    });
  } catch (err) {
    console.error(err);
    alert(err.message);
  }
};

动作代码设置:

const actionCodeSettings = {
  // URL you want to redirect back to. The domain (www.example.com) for this
  // URL must be in the authorized domains list in the Firebase Console.
  url: "/",
  // This must be true.
  handleCodeInApp: true,
  iOS: {
    bundleId: "com.example.ios",
  },
  android: {
    packageName: "com.example.android",
    installApp: true,
    minimumVersion: "12",
  },
  //dynamicLinkDomain: "example.page.link",
};

问题可能在于 actionCodeSettings,我希望我的网站在执行注册后重定向到 root。 顺便说一下,我在本地托管这个网站,它是不公开的。

提前致谢!

错误意味着

continue URL 必须是有效的 URL 字符串。

所以......你没看错, /是一个有效的 URL 字符串。 但是响应“Missing domain in continue url”表明它必须是绝对的 URL。因此这是无效的:

  // URL you want to redirect back to. The domain (www.example.com) for this
  // URL must be in the authorized domains list in the Firebase Console.
  url: "/",

将您网站的完整 URL 放在那里,包括http://https://和域名。 并且,正如评论中提到的,确保它在 Firebase 控制台中获得授权。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM