【问题标题】:I want to get the userid from firebase when i enter the email in ionic当我在 ionic 中输入电子邮件时,我想从 firebase 获取用户 ID
【发布时间】:2019-10-12 09:29:10
【问题描述】:

我正在设置搜索方法。所以我想在输入特定帐户的 email 时从身份验证中获取 userid

注意:我已经使用 createUserWithEmailAndPassword 方法注册了用户..

【问题讨论】:

标签: angular firebase ionic2 ionic3 firebase-authentication


【解决方案1】:

为了使用搜索功能,您需要一个所有用户的列表。并且可以通过邮箱获取用户的uid。

您可以使用 firebase admin sdk 来做到这一点。 https://firebase.google.com/docs/auth/admin/manage-users

它有一个listusers函数:

admin.auth().listUsers(1000, nextPageToken)
    .then(function(listUsersResult) {
      listUsersResult.users.forEach(function(userRecord) {
        console.log('user', userRecord.toJSON());
      });
      if (listUsersResult.pageToken) {
        // List next batch of users.
        listAllUsers(listUsersResult.pageToken);
      }
    })
    .catch(function(error) {
      console.log('Error listing users:', error);
    });

还有getuserbyemail功能:

admin.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);
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    • 2019-06-25
    • 2020-10-31
    • 2021-04-04
    • 2019-11-25
    • 2018-12-19
    • 2017-05-30
    相关资源
    最近更新 更多