我终于使用我的身份验证来创建用户和登录和注销 . 但现在,我想实现一些检查用户是否已存在于Firebase中的内容 . 我查了一下,但似乎找不到具体的答案 .
例如,如果我的电子邮件地址是:abc12@gmail.com而其他人尝试使用相同的电子邮件地址注册,我该如何告诉他们已经使用了?
login(e) {
e.preventDefault();
fire.auth().signInWithEmailAndPassword(this.state.email, this.state.password)
.then((u) => {
}).catch((error) => {
console.log(error);
});
}
signup(e) {
e.preventDefault();
fire.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
.then((u) => {
}).catch((error) => {
console.log(error);
});
}
1 回答
从方法
createUserWithEmailAndPassword
返回的错误具有code
属性 . 根据documentation错误code
auth/email-already-in-use :您至少可以使用
if
/else
或switch
等条件语句来检查code
并向用户显示/ log / dispatch / etc消息或代码:希望这有帮助!