Created
August 28, 2019 17:24
-
-
Save samueladesoga/7ddc3624afa5e1d38e80aa04baeb386b to your computer and use it in GitHub Desktop.
Delete Firebase Auth User
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
let admin = require('firebase-admin') | |
let serviceAccount = require('../.google-service-keys.default.json') | |
admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount), | |
databaseURL: `https://${serviceAccount.project_id}.firebaseio.com`, | |
}) | |
function deleteUser(uid) { | |
admin | |
.auth() | |
.deleteUser(uid) | |
// eslint-disable-next-line promise/always-return | |
.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) { | |
let uid = userRecord.toJSON().uid | |
deleteUser(uid) | |
}) | |
// eslint-disable-next-line promise/always-return | |
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