我终于让我的身份验证在创建用户和登录和注销方面起作用。但是现在,我想实现一些检查用户是否已经存在于 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);
});
}
原文由 sp92 发布,翻译遵循 CC BY-SA 4.0 许可协议
从方法
createUserWithEmailAndPassword
返回的错误具有code
属性。根据 文档 错误code
auth/email-already-in-use :At very minimum you can utilize conditional statements such as
if
/else
orswitch
to check for thatcode
and display/log/dispatch /etc 给用户的消息或代码:希望这有帮助!