javascript - Firebase 登录 - 检查电子邮件是否在使用中
问题描述
我被困在这个问题上。当我尝试为我正在创建的注册页面输入相同的电子邮件和不同的密码时,我没有收到相同的电子邮件被使用错误,但是当我使用相同的电子邮件和密码时,它会显示电子邮件正在使用中。即使密码不同,我该如何让它显示正在使用的电子邮件?
谢谢
这是我的代码:
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.
});
}
解决方案
要检测电子邮件是否已在使用中,请不要调用createUserWithEmailAndPassword
,而是调用fetchSignInMethodsForEmail
。
推荐阅读
- azure - 使用 Powershell/AzCopy 将文件从 Azure 文件存储移动到 Dropbox
- c# - 使用 Polly 重试和断路器模式
- mysql - 如何在我的 sql 表中存储超过 838:59:59 的时间值
- sql - 如何向所有部门显示 2014 年 3 月销售价格低于 400 的商品
- django - Django 模板:使用 include 传递表单模板;表格怎么写?
- ios - 在 Table View Controller 中水平滚动 UITableView
- reactjs - 使用路由还是状态?
- angular - 如何订阅和更新深层嵌套在 BehaviorSubject 中的单个属性?
- c++ - 为什么通过指针初始化创建对象实例时std :: string属性为空
- java - 我如何解决jframe期间的java致命错误