Last active
June 11, 2022 02:37
-
-
Save joshpetit/b6cf918a9beac1f4e86270475a61cb11 to your computer and use it in GitHub Desktop.
Deletes all the users in firebase. Max 8,000 at a time
This file contains hidden or 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
var admin = require('firebase-admin'); | |
var serviceAccount = require("./service-account.json"); | |
admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount), | |
databaseURL: "/url/to/your/database" | |
}); | |
function deleteUser(uid) { | |
admin.auth().deleteUser(uid) | |
.then(function() { | |
console.log('Successfully deleted user', uid); | |
}) | |
.catch(function(error) { | |
console.log('Error deleting user:', error); | |
}); | |
} | |
function getAllUsers(nextPageToken) { | |
admin.auth().listUsers(100, nextPageToken) | |
.then(function(listUsersResult) { | |
listUsersResult.users.forEach(function(userRecord) { | |
uid = userRecord.toJSON().uid; | |
deleteUser(uid); | |
}); | |
if (listUsersResult.pageToken) { | |
getAllUsers(listUsersResult.pageToken); | |
} | |
}) | |
.catch(function(error) { | |
console.log('Error listing users:', error); | |
})}; | |
getAllUsers(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment