Skip to content

Instantly share code, notes, and snippets.

@hiranya911
Created May 7, 2020 00:16
Show Gist options
  • Save hiranya911/3ed4c4e33de281f23296410a802043ce to your computer and use it in GitHub Desktop.
Save hiranya911/3ed4c4e33de281f23296410a802043ce to your computer and use it in GitHub Desktop.
const admin = require('firebase-admin');
admin.initializeApp();
// Lookup user accounts by uid, email, phone number of IdP-assigned uid.
// List up to 100 identifiers to lookup.
const uids = [
{uid: 'sample-uid-1'},
{uid: 'sample-uid-2'},
{email: '[email protected]'},
{phoneNumber: '+1234567890'},
{providerId: 'google.com', providerUid: '[email protected]'},
];
const markedForDelete = [];
// Retrieve a batch of user accounts.
admin.auth().getUsers(uids)
.then((result) => {
// Mark disabled accounts for deletion.
result.users.forEach((user) => {
if (user.disabled) {
markedForDelete.push(user.uid);
}
});
result.notFound.forEach((uid) => {
console.log(`No user found for identifier: ${JSON.stringify(uid)}`)
});
})
.then(() => {
// Delete all marked user accounts in a single API call.
return admin.auth().deleteUsers(markedForDelete);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment