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
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.
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.
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.databaseURL
from the settings page. Replace it in the code.index.js
.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();
firebaser here
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:
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")
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
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.
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.