Delete all users from firebase auth console

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 all of them.


Solution 1:

As in updated answer, you can probably use firebase admin tools now, but if you don't want – here is a bit more solid javascript to remove users in the web:

var intervalId;

var clearFunction = function() {
  var size = $('[aria-label="Delete account"]').size()
  if (size == 0) {
    console.log("interval cleared")
    clearInterval(intervalId)
    return
  }
  var index = Math.floor(Math.random() * size)
  $('[aria-label="Delete account"]')[index].click();
  setTimeout(function () {
     $(".md-raised:contains(Delete)").click()
  }, 1000);
};

intervalId = setInterval(clearFunction, 300)

Just run it in developer tools

Solution 2:

Because I'm pretty lazy at clicking buttons and elements in the UI, I set up a small client script:

$('[aria-label="Delete account"]').click()
setTimeout(function () {
   $(".md-raised:contains(Delete)").click()
}, 1000);

You may need to run it multiple times, but it is much better than wasting the time clicking things on the screen manually.

Solution 3:

For the new Firebase update

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()
    let deleteButtonPosition = document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted').length - 1
    document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted')[deleteButtonPosition].click()
    document.getElementsByClassName('confirm-button mat-focus-indicator mat-raised-button mat-button-base mat-warn')[0].click()
}, 1000)

Solution 4:

Here is my bicycle: 😄

setInterval(() => {
  $('[aria-label="Delete account"]').first().click()
  setTimeout(()=>{
    $(".md-raised:contains(Delete)").click()
  }, 100)
}, 2000);

designed to avoid calling delete endpoint very often, since google fails with 404 error.

Solution 5:

Fully working solution using Firebase Admin SDK

Using the Firebase Admin SDK is really easy and the recommended way to perform such tasks on your Firebase data. This solution is unlike the other makeshift solutions using the developer console.

I just put together a Node.js script to delete all users in your Firebase authentication. I have already tested it by deleting ~10000 users. I simply ran the following Node.js code.

To setup Firebase Admin SDK

Create a new folder. Run the following in terminal

npm init
sudo npm install firebase-admin --save

Now create an index.js file in this folder.

Steps to follow:

  • Go to your Firebase project -> Project Settings -> Service Accounts.
  • Click on Generate new Private Key to download the JSON file. Copy the path to JSON file and replace it in the code below in the path to service accounts private key json file.
  • Also, copy the databaseURL from the settings page. Replace it in the code.
  • Copy and paste the code in index.js.
  • Run in terminal node index.js. Watch the mayhem!
var admin = require('firebase-admin');

var serviceAccount = require("/path/to/service/accounts/private/key/json/file");

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "/url/to/your/database"
});

function deleteUser(uid) {
    admin.auth().deleteUser(uid)
        .then(function() {
            console.log('Successfully deleted user', uid);
        })
        .catch(function(error) {
            console.log('Error deleting user:', error);
        });
}

function getAllUsers(nextPageToken) {
    admin.auth().listUsers(100, nextPageToken)
        .then(function(listUsersResult) {
            listUsersResult.users.forEach(function(userRecord) {
                uid = userRecord.toJSON().uid;
                deleteUser(uid);
            });
            if (listUsersResult.pageToken) {
                getAllUsers(listUsersResult.pageToken);
            }
        })
        .catch(function(error) {
            console.log('Error listing users:', error);
        });
}

getAllUsers();