Firebase:当电子邮件确实存在时出现错误 (auth/missing-email)。反应堆
Firebase: Error (auth/missing-email) when the email definetly exists. Reactjs
这是我的代码:
function loginWithEmailHandler() {
signInWithEmailAndPassword(auth)
.then((result) => {
const user = result.user;
console.log(user.email, user.displayName);
navigate("/");
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
setMode("INCORRECT");
console.log(errorCode, errorMessage);
});
}
当我 运行 在我的 LoginForm.js 中使用此函数时,它给出了标题中所述的错误。我不知道如何检查它是否检查了正确的电子邮件,所以我有点卡在这里。
signInWithEmailAndPassword()
需要 3 个参数 - 身份验证实例、电子邮件和密码。但是你只通过了第一个。尝试重构代码,如下所示:
function loginWithEmailHandler(email, password) {
signInWithEmailAndPassword(auth, email, password)
.then((result) => {
const user = result.user;
console.log(user.email, user.displayName);
navigate("/");
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
setMode("INCORRECT");
console.log(errorCode, errorMessage);
});
}
确保您传递了用户在该函数中输入的电子邮件和密码:
// While calling the function
loginWithEmailHandler('user@domain.tld', 'userPassword');
您可以在 documentation 阅读更多内容。
这是我的代码:
function loginWithEmailHandler() {
signInWithEmailAndPassword(auth)
.then((result) => {
const user = result.user;
console.log(user.email, user.displayName);
navigate("/");
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
setMode("INCORRECT");
console.log(errorCode, errorMessage);
});
}
当我 运行 在我的 LoginForm.js 中使用此函数时,它给出了标题中所述的错误。我不知道如何检查它是否检查了正确的电子邮件,所以我有点卡在这里。
signInWithEmailAndPassword()
需要 3 个参数 - 身份验证实例、电子邮件和密码。但是你只通过了第一个。尝试重构代码,如下所示:
function loginWithEmailHandler(email, password) {
signInWithEmailAndPassword(auth, email, password)
.then((result) => {
const user = result.user;
console.log(user.email, user.displayName);
navigate("/");
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
setMode("INCORRECT");
console.log(errorCode, errorMessage);
});
}
确保您传递了用户在该函数中输入的电子邮件和密码:
// While calling the function
loginWithEmailHandler('user@domain.tld', 'userPassword');
您可以在 documentation 阅读更多内容。