Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Nuke a Firebase Database and All User Accounts Referenced Therein
// NOTE: Accounts that are not represented in your /users node will not be deleted!
// BLOG: There are other approaches, see:
"use strict";
// Get credentials and initialize firebase app
console.log("With the power vested in the admin user, lay waste the database and all its users!");
let admin = require("firebase-admin");
let serviceAccount = require([__dirname, "service-account-key.json"].join('/'));
credential: admin.credential.cert(serviceAccount),
databaseURL: ""
// Fetch the /users node and begin deleting users.
// Finally, wipe the database.
let user, users = [];
let usersRef = admin.database().ref('/users');
usersRef.once('value').then( (snapshot) => {
// Get an Array of users from the DatabaseSnapshot
snapshot.forEach( (childSnapshot) => {
user = childSnapshot.val();
console.log(users.length + " users retrieved");
// Delete users then wipe the database
if (users.length > 0) {
// Now map users to an Array of Promises
console.log("Delete users... ");
let promises = => deleteUser(user));
// Wait for all Promises to complete before wiping db
.catch( e => console.log(e.message) );
} else {
// If no users to delete, then just wipe database
// Delete a user
// Promise always resolves, even if user doesn't exist,
// since a user can be deleted separately from their /users node
function deleteUser(user) {
return new Promise((resolve, reject) => {
console.log("Delete user: " + + "");
.then( () => {
console.log( + " deleted.");
.catch( e => {
console.log([e.message,, "could not be deleted!"].join(' '));
// Wipe the database by removing the root node
function wipeDatabase() {
console.log("Wiping database... ");
.then( () => {
.catch( e => {
"type": "service_account",
"project_id": "your-db-name-here",
"private_key_id": "b4158530b6255bd098369aa94f2313a60e1aa534",
"private_key": "-----BEGIN PRIVATE KEY-----\nyour-private-key-here\n-----END PRIVATE KEY-----\n",
"client_email": "",
"client_id": "your-client-id-here",
"auth_uri": "",
"token_uri": "",
"auth_provider_x509_cert_url": "",
"client_x509_cert_url": ""

This comment has been minimized.

Copy link

@chetstone chetstone commented Sep 9, 2018

Hmm. It deleted a few accounts, then started spitting out: "QUOTA_EXCEEDED : Exceeded quota for deleting accounts." Then it wiped the database and I had to go delete all the user accounts one by one in the console.


This comment has been minimized.

Copy link

@chetstone chetstone commented Sep 24, 2018

Firebase account deletions are limited to 10/sec.

I created a fork that just deletes the first 10 users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.