[英]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.