Admin SDK无法获取通话中的用户列表

时间:2018-09-04 19:12:03

标签: javascript node.js firebase firebase-authentication firebase-admin

嗨,我有以下内容,并试图获取用户列表

exports.listAllUsers = functions.https.onCall((req, res) => {
  // List batch of users, 1000 at a time.
  return listAllUsers();
});

function listAllUsers(){
 var allUsers = [];

  return admin.auth().listUsers()
    .then(function (listUsersResult) {
      listUsersResult.users.forEach(function (userRecord) {
        // For each user
        var userData = userRecord.toJSON();
        allUsers.push(userData);
      });
      res.status(200).send(JSON.stringify(allUsers));
    })
    .catch(function (error) {
      console.log("Error listing users:", error);
      res.status(500).send(error);
    });   
}

在网页中,调用时显示错误

$('#buttonID').click(function () {
                var listAllUsers = firebase.functions().httpsCallable('listAllUsers');
                listAllUsers({}).then(function(result) {
                    console.log(result);
                });

            });

任何想法

0 个答案:

没有答案