Created
May 7, 2020 00:16
-
-
Save hiranya911/3ed4c4e33de281f23296410a802043ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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