0

I have read the documentation about listing all users via admin SDK but still struggling to show users in my vue component...

the code in the documentation is:

function listAllUsers(nextPageToken) {
  // List batch of users, 1000 at a time.
  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);
    });
});
// Start listing users from the beginning, 1000 at a time.
 listAllUsers();

in my component, I want to create an array that will contain all users and display them,.. The question is,.. How would I do that? is it by an axios request? and what are the steps?

Nasr Galal
  • 31
  • 6

1 Answers1

1

As explained in the documentation "the Admin SDK supports Node.js, Java, and Python." This means that you cannot use the code in your question directly in a Vue.js component. You need to execute this code in a backend and call this backend from your Vue.js component.

One of the standard solution would be to create a Callable Cloud Function that executes this code and returns the list of users as an array. The documentation explains how to implement such a function and how to call it from your vue.js application (See here).

You could also use a "standard" HTTPS Cloud Function and call it via Axios, but using a Callable Cloud Functions brings some extra advantages as explained in the doc ("Firebase Authentication and FCM tokensare automatically included in requests, the functions.https.onCall trigger automatically deserializes the request body and validates auth tokens.", etc...).

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
  • Thank you so much! So as I understood, If I am using nodejs for example, I should write the main code provided and export it as a callable function, then I execute the the code from the component via request... Is that correct? – Nasr Galal Sep 05 '19 at 00:00
  • 1
    Yes that’s it! You may have a look at https://firebase.google.com/docs/functions/get-started?hl=en to start working with Cloud Functions. – Renaud Tarnec Sep 05 '19 at 05:06
  • 1
    That's even easier than I thought! Thanks a lot! – Nasr Galal Sep 05 '19 at 13:58