Angular, Firebase deleteUser() not deleting anonymous users in prod, works in dev project

  angular, firebase, google-cloud-functions

running into a weird situation with a Firebase function. I am trying to cleanup anonymous users and I have used the code below

// Delete all Anonymous Users
export const cleanupUsers = functions.pubsub.schedule('01 00 * * *')
.timeZone('America/Los_Angeles') // Users can choose timezone - default is America/Los_Angeles
.onRun(async context => {
  //Get the list of all Users
  const allUsers = await admin.auth().listUsers();
  allUsers.users.forEach(async(user) => {
    console.log('This USER has been read: ', user.email, user.providerData.length);
    if (user.providerData.length === 0) {
      console.log('This USER will now be deleted: ', user.email, user.uid);
      await admin.auth().deleteUser(user.uid).then(res => {
        console.log('This USER has been deleted: ', res);
      }).catch(err => console.log('Error on delete of user', err));
    }
  });
});

Strange thing is that it works on my "dev" project in Firebase, but when I deploy the same function to my prod project it does not delete the anonymous users. I don’t get an error, it just doesn’t do the delete user part. Here is part of the log:

1:05:11.793 PM cleanup-cleanupUsers
This USER has been read:  undefined 0 
1:05:11.793 PM cleanup-cleanupUsers
This USER will now be deleted: undefined b79lTv0ckeR67IlNXSnNEGr0ZfD2
1:05:11.891 PM cleanup-cleanupUsers
Function execution took 1004 ms, finished with status: 'ok'

As you can see by the log, it does read the anonymous user, it knows the uid, but for some reason, in prod only, it doesn’t delete the user.

Any ideas as to why it doesn’t do the delete?

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.