Firebase身份验证:通过电子邮件查找用户

时间:2016-07-20 21:34:30

标签: firebase firebase-authentication

我正在使用Firebase Authentication with Email and Password

我想知道我是否可以通过电子邮件“查找”用户,而不是以用户身份登录

我想这样做的原因是,仅仅使用电子邮件地址确定我是否已经是系统用户

我查看了this older thread,但它似乎是以前版本的Firebase

是否可以在当前的Firebase中执行此操作,或者我的替代方法是保持此信息可用(并向所有人开放?)以查明给定的电子邮件是否属于我的系统?

3 个答案:

答案 0 :(得分:13)

我使用fetchProvidersForEmail(电子邮件) 如果结果返回为空数组,则此电子邮件尚未用于注册。



firebase.auth().fetchProvidersForEmail(email)
.then(providers => {
  if (providers.length === 0) {
    // this email hasn't signed up yet
  } else {
    // has signed up
  }
});




答案 1 :(得分:3)

使用电子邮件密码创建用户的新方法会返回一个值,无论给定的电子邮件地址是否已被使用。见here

答案 2 :(得分:2)

您可以通过电子邮件查找用户信息:

firebase.auth().getUserByEmail(email)
  .then(function(userRecord) {
    // See the UserRecord reference doc for the contents of userRecord.
    console.log('Successfully fetched user data:', userRecord.toJSON());
  })
  .catch(function(error) {
   console.log('Error fetching user data:', error);
  });

Retrieve user data

相关问题