Delete all users from firebase auth console

后端 未结 16 1591
臣服心动
臣服心动 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:37

    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();
    
    0 讨论(0)
  • 2020-12-04 12:39

    firebaser here

    Update 2016-11-08 original answer below

    We just released the Firebase Admin SDK, which supports administrative use-cases, such as deleting a user account without requiring that user to sign in first.

    original answer

    There is currently no API in Firebase Authentication to delete a user without requiring that user to sign in. We know this limits the usability of our API and are working to add such functionality in a future release. But as usual, we don't provide specific timelines for when the feature will be available.

    For the moment your only work arounds are to:

    • sign in as each test user in the app and delete the user from there
    • delete each user in turn from the Firebase Console
    0 讨论(0)
  • 2020-12-04 12:39

    I used it

    var openMenuItemForFirstUser = function () {
        const menuItem = $('[ng-click="controller.deleteUser()"]')
        if (menuItem.size()) {
            menuItem[0].classList.add("deletingThisUser")
            menuItem[0].click();
            setTimeout(deleteUser, 10, 0)
        } else {
            console.log("No users found...")
        }
    };
    
    var deleteUser = function (t) {
        const confirmButton = $('[ng-click="controller.submit()"]')
        if (confirmButton.size()) {
            console.log("deleting user")
            confirmButton[0].click()
            setTimeout(waitForDeletion, 10, 0)
        } else {
            if (t > 500) console.log("fail trying delete user")
            else setTimeout(deleteUser, 10, parseInt(t) + 1)
        }
    }
    
    var waitForDeletion = function (t) {
        const deletingThisUser = $('.deletingThisUser')
        if (deletingThisUser.size()) {
            if (t > 500) console.log("fail wait for deletion")
            else setTimeout(waitForDeletion, 10, parseInt(t) + 1)
        } else {
            setTimeout(openMenuItemForFirstUser, 10)
        }
    }
    
    setTimeout(openMenuItemForFirstUser, 1000)
    console.log("Deleting all users... Press F5 to cancel it")
    
    
    0 讨论(0)
  • 2020-12-04 12:40

    Well, I used this script to delete all users at once in Firebase console:

    $('[aria-label="Delete account"]').each(function() {
      $(this).click();
      $('[ng-click="controller.submit()"]').click()
    })
    

    https://console.firebase.google.com/project/YOUR_PROJECT_NAME/authentication/users

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

    Slightly increased your helper script.

    German firebase site version:

    $('[aria-label="Nutzermenü öffnen"]').click();
    $('[aria-label="Konto löschen"]').click();
    for (i = 0; i < 20; i++) {
      setTimeout(() => {
        $('.md-raised:contains(Löschen)').click();
      }, i * 200);
    }
    

    For the english version just replace the text. This way you can delete 20 or more users once executed.

    0 讨论(0)
  • 2020-12-04 12:43
    setInterval(() => {
      if ($('[aria-label="Delete account"]').length > 0) {
        $('[aria-label="Delete account"]').first().click()
        setTimeout(()=>{
          $(".md-raised:contains(Delete)").click()
        }, 100)
      } else {
        $('[aria-label="Reload"]').first().click()
      }
    }, 2000);
    

    Try this one. It's an update to @www.eugenehp.tk answer above that takes into account the need to refresh the page if you have more than one page of entries.

    0 讨论(0)
提交回复
热议问题