How do I return a list of users if I use the Firebase simple username & password authentication

后端 未结 7 2075
猫巷女王i
猫巷女王i 2020-11-22 05:06

Not sure if I am doing something wrong but using this api https://www.firebase.com/docs/security/simple-login-email-password.html I can successfully create a user - accordin

7条回答
  •  旧巷少年郎
    2020-11-22 05:16

    You can do it using admin.auth().listUsers

    Here is the doc for this: https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth.html#listusers

    And an usage example: https://firebase.google.com/docs/auth/admin/manage-users#list_all_users

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

提交回复
热议问题