我被这个问题困住了。当我尝试为我创建的注册页面输入相同的电子邮件和不同的密码时,我没有收到相同的电子邮件被使用错误,但是当我使用相同的电子邮件和密码时,它说电子邮件正在使用中。即使密码不同,我该如何设置才能显示电子邮件正在使用中?
谢谢
这是我的代码:
function signUp(email,password){
//Check if email adress registerd then password security
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error){
var errorCode = error.code;
console.log(error.message, errorCode)
if(errorCode == "auth/weak-password"){
alert("Password too weak")
}
else if(errorCode == "auth/email-already-in-use"){
alert("Email in use aldready")
}
else{
//If succsess
firebase.auth().sendSignInLinkToEmail(email, actionCodeSettings).then(() => {
window.localStorage.setItem('emailForSignIn', email);
}).catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
});
}
})
}
编辑: 我尝试使用 fetch 方法,但还是遇到了同样的问题
function signUp(email,password){
//Check if email adress registerd then password security
firebase.auth().fetchSignInMethodsForEmail(email)
.then((signInMethods) => {
if (signInMethods.length) {
alert("Aldready signed up with this email")
} else {
// User does not exist. Ask user to sign up.
}
})
.catch((error) => {
// Some error occurred.
});
}
答案 0 :(得分:0)
要检测电子邮件是否已被使用,请不要调用 createUserWithEmailAndPassword
,而是调用 fetchSignInMethodsForEmail
。