I am trying to use Firebase Admin SDK to delete authenticated users. All the users can be deleted using this. However, I only want to delete those authenticated with a specific auth service provider, i.e., delete users authenticated with Google/Facebook and leave the ones who signed in using email.
Asked
Active
Viewed 140 times
1 Answers
0
You can try something like this...
function listAllUsers(nextPageToken) {
// List batch of users, 1000 at a time.
admin.auth().listUsers(1000, nextPageToken)
.then(function(listUsersResult) {
listUsersResult.users.forEach(function(userRecord) {
//Check if the user signed in with Google/Facebook
if (userRecord.providerId == "Google" || userRecord.providerId == "Facebook") {
//Delete user
admin.auth().deleteUser(userRecord.uid)
}
});
if (listUsersResult.pageToken) {
// List next batch of users.
listAllUsers(listUsersResult.pageToken);
}
})
.catch(function(error) {
console.log('Error listing users:', error);
});
}
// Start listing users from the beginning, 1000 at a time.
listAllUsers();
This is untested, so I'm not sure if this exact code will work, but you get the idea.

nachshon f
- 3,540
- 7
- 35
- 67