简体   繁体   English

使用 Node.js 列出 Firebase iOS 应用中的所有用户

[英]Using Node.js to list all users in a Firebase iOS App

I am trying to create a list of all my firebase users in node.js.我正在尝试在 node.js 中创建我所有 firebase 用户的列表。 I am following the description as offered on https://firebase.google.com/docs/auth/admin/manage-users我正在遵循https://firebase.google.com/docs/auth/admin/manage-users 上提供的描述

When running the below code, I throws an error saying运行下面的代码时,我抛出一个错误说

TypeError: admin.auth(...).listUsers is not a function

I have a suspicion that the firebase documentation uses 'admin' in different ways in different places and that the 'admin' I use below from initialisation is not the one I should be using to list the users, but I can't quite work out how to correct it.我怀疑 firebase 文档在不同的地方以不同的方式使用“admin”,并且我在下面从初始化使用的“admin”不是我应该用来列出用户的那个,但我不能完全解决如何纠正它。 The documentation is not very clear.文档不是很清楚。

Please note that for the .initializeApp({...}) code I added some '...' where otherwise I have the correct text.请注意,对于.initializeApp({...})代码,我添加了一些“...”,否则我有正确的文本。

var admin = require('firebase-admin');
var serviceAccount = require('../serviceAccountKey');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: 'https://...',
  databaseAuthVariableOverride: {
    uid: ' ... ',
  },
});

const db = admin.database();
const refUsersServer = db.ref('usersServer');

function listAllUsers(nextPageToken) {
  // List batch of users, 1000 at a time.
  // admin.auth().listUsers(1000, nextPageToken)

  admin.auth().listUsers(1000, nextPageToken)
    .then(function(listUsersResult) {
      listUsersResult.users.forEach(function(userRecord) {
        console.log("user", userRecord.toJSON());
      });

      // List next batch of users.
      if (listUsersResult.pageToken) {
        listAllUsers(listUsersResult.pageToken)
      }
    })
    .catch(function(error) {
      console.log("Error listing users:", error);
    });
}

// Start listing users from the beginning, 1000 at a time.
listAllUsers();

The code works fine but only in the latest firebase-admin version.该代码工作正常,但仅适用于最新的 firebase-admin 版本。 In the earlier versions, the listUsers function didn't exit.在早期版本中,listUsers 函数没有退出。

My mistake was that I didn't run the latest firebase-admin version which thanks to David 'G' I realised.我的错误是我没有运行最新的 firebase-admin 版本,这要感谢 David 'G' 我意识到。 Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM