Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving a list of users who have registered using Firebase Auth

I am making an android chat application using firebase. So far I have made a common group chat app. Now I want to make it an individual chat app, which will have a Users list and when we select a person from that list we can chat individually with him/her. However I am not able to get this Users list from Firebase. I have kept Google Sign in and Email sign in options in the Firebase Auth UI. Any help would be appreciated

like image 882
user8802646 Avatar asked Oct 25 '17 18:10

user8802646


2 Answers

If you need to lookup users by uid, email or phoneNumber, you can use the Admin SDK to do so:

https://firebase.google.com/docs/auth/admin/manage-users

You also even have the ability to download all your users: https://firebase.google.com/docs/auth/admin/manage-users#list_all_users

You would need to do that from a Node.js backend server or via HTTP endpoints with Firebase Functions.

In addition the Admin SDK allows you to set custom user attributes which could be helpful if you want to create different user groups:

https://firebase.google.com/docs/auth/admin/custom-claims

admin.auth().setCustomUserClaims(uid, {groupId: '1234'})

like image 105
bojeil Avatar answered Sep 28 '22 09:09

bojeil


The Firebase Admin SDK allows retrieving the entire list of users in batches:

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();

Note: This API is currently only available for the Admin Node.js SDK.

via https://firebase.google.com/docs/auth/admin/manage-users

like image 41
Aspen Avatar answered Sep 28 '22 08:09

Aspen