Delete all users from firebase auth console

后端 未结 16 1592
臣服心动
臣服心动 2020-12-04 11:53

Is there an easy way to delete all registered users from firebase console? For example, I created a hundred users from my development environment, and now I want to delete a

相关标签:
16条回答
  • 2020-12-04 12:43

    For the new Firebase update (13.11.2020)

    Try this code for the latest Firebase update. Open the console, paste this code and hit enter!!!

    setInterval(() => {
        document.getElementsByClassName('edit-account-button mat-focus-indicator mat-menu-trigger mat-icon-button mat-button-base')[0].click()
        document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted')[2].click()
        document.getElementsByClassName('confirm-button mat-focus-indicator mat-raised-button mat-button-base mat-warn')[0].click()
    }, 1000)
    
    0 讨论(0)
  • 2020-12-04 12:44

    A solution that worked for me was to create a separate file and import my firebase-admin and simply run the following:

    const admin = require('./firebase_admin');
    
    const listAllUsers = () => {
      console.log('list all users');
      // List batch of users, 1000 at a time.
      admin.auth().listUsers(1000)
        .then((listUsersResult) => {
          listUsersResult.users.forEach((userRecord) => {
            const user = userRecord.toJSON();
            admin
              .auth()
              .deleteUser(user.uid)
              .then(() => {
                console.log('successfully deleted user');
              })
              .catch((err) => {
                console.error('error deleting user: ', err);
              });
          });
          if (listUsersResult.pageToken) {
            // List next batch of users.
            listAllUsers(listUsersResult.pageToken);
          }
        })
        .catch((error) => {
          console.log('Error listing users:', error);
        });
    };
    // Start listing users from the beginning, 1000 at a time.
    listAllUsers();
    

    The concept here is that we want to retrieve all the users from our user auth table, then cycle throw and delete them one at a time using the deleteUser admin auth method.

    In the terminal, I simply used node to call the function in the file (so let's say the filename is delete_users.js, I just called node delete_users.js and the listUsers function was invoked.

    Hope this helps.

    0 讨论(0)
  • 2020-12-04 12:47

    Used this code successfully on 11/16/2020:

    setInterval(function () {
        $('[aria-label="View more options"]')[0].click()
        document.querySelectorAll('.mat-menu-item')[2].click()
        document.querySelector('.confirm-button').click()
    }, 1000);
    
    0 讨论(0)
  • 2020-12-04 12:47

    Try this,

     var elements = [];
      $('.a12n-users-table').find('tr').each(function(r){
       $(this).find('td.table-row-actions').each(function(tds) {
        $(this).find('button').each(function(x){
            if($(this).attr('aria-label')=="Delete account"){
                elements.push($(this));
            }
        });
       });
      });
    
       var index = 0;
         function deleteUser(){
          index++;
          elements[index].click();
          $('.fb-dialog-actions').find('.md-warn').click();
          setTimeout(deleteUser, 5000); 
       }
      deleteUser();
    
    0 讨论(0)
提交回复
热议问题