firebase-authentication - 电子邮件的 Firebase 身份验证检查已经存在,但不使用 signInWithEmailAndPassword
问题描述
我想检查firebase auth服务器中是否已经存在电子邮件,然后向用户询问密码。
有一个众所周知的解决方案是使用 signInWithEmailAndPassword 方法并依赖于错误消息。但在这种情况下,如果电子邮件不存在,它将创建一个帐户。我不想创建一个帐户,我只想知道电子邮件是否已经存在。
我应该为此使用云功能吗?我怎样才能做到这一点 ?
解决方案
您可以使用fetchSignInMethodsForEmail
. 这是一个使用 JavaScript 的示例:
firebase.auth().fetchSignInMethodsForEmail(email)
.then((signInMethods) => {
if (signInMethods.length) {
// The email already exists in the Auth database. You can check the
// sign-in methods associated with it by checking signInMethods array.
// Show the option to sign in with that sign-in method.
} else {
// User does not exist. Ask user to sign up.
}
})
.catch((error) => {
// Some error occurred.
});
推荐阅读
- java - Ibatis 结果图不适用于内部类
- youtube - Youtube 数据配额是限制为 10k 单位/天/应用程序,还是 10k 单位/天/用户?
- javascript - Jest 中的 Mock shell 命令输出
- python - 自定义模型字段在哪里转换为它们的 db_type?
- wpf - 鼠标移动失控时禁用按钮
- python - 在 matplotlib 中为散点图提供旋转的更快方法?
- python - 如果 while 循环处于活动状态,海龟图形不响应 onkey() 命令
- javascript - 使用 javascript partial.lenses 获取数组中的属性时遇到问题
- dart - 在 Flutter 中正确使用 MediaQuery
- ios - UIViewControllerTransitioningDelegate 在呈现后立即被取消初始化