Reputation: 175
No matter what i tried, I could not delete users from Firebase Cloud Function.
I can list all users, but deleteUsers
function always return error for no reason.
Try number 1 :
exports.removeUsers = functions.https.onRequest(async(request, response) => {
cors(request, response, async () => {
const allUsers = await auth.listUsers();
const allUsersUID = allUsers.users.map((user) => user.uid);
return auth.deleteUsers(allUsersUID).then(() => response.send("deleted"));
});
});
Try number 2 no async
inside :
//list 1000 users
var nextPageToken;
const usersToDelete = [];
admin.auth().listUsers(1000, nextPageToken).then(function(listUsersResult) {
listUsersResult.users.forEach(function(userRecord) {
var userID = userRecord.toJSON().uid;
usersToDelete.push(userID);
});
return;
}).then(() => {
console.log(usersToDelete.length);
return admin.auth().deleteUsers(usersToDelete);
}).catch(function(error) {
console.log('Error listing users:', error);
});
Both functions will list all users (880), but will show error on functions logs saying :
Error listing users: TypeError: admin.auth(...).deleteUsers is not a function
Not sure why this is not a function, start to think Google just don't like you deleting all of your users.
Upvotes: 0
Views: 299
Reputation: 598728
Check the version of the Admin SDK you are using, as deleteUsers
was added relatively recently in version 8.12 of the Node.js SDK.
Upvotes: 1