Skip to content

Instantly share code, notes, and snippets.

@katowulf
Created March 6, 2018 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katowulf/da4e3d461e19a4795d6c43ac59dc5d08 to your computer and use it in GitHub Desktop.
Save katowulf/da4e3d461e19a4795d6c43ac59dc5d08 to your computer and use it in GitHub Desktop.
Delete users in Firebase Authentication using Admin SDK
const admin = require('firebase-admin');
const serviceAccount = require('path/to/serviceAccountKey.json');
// User IDs to be deleted
const UIDs = [];
// initialize the app
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'
});
// establish an interval to throttle requests
const originalCount = UIDs.length;
const intervalRef = setInterval(processNextTen, 1001);
function processNextTen() {
const uids = UIDs.splice(-10, 10);
if( uids.length ) {
const completed = originalCount - UIDs.length;
console.log(`[${completed}/${originalCount}] Deleting ${uids}`);
uids.forEach(deleteUser);
}
else {
cleanup();
}
}
function deleteUser(uid) {
admin.auth().deleteUser(uid)
.catch(function(error) {
console.log("Error deleting user", uid, error);
});
}
function cleanup() {
clearInterval(intervalRef);
console.log('finished');
process.exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment