How to bulk delete Firebase anonymous users

后端 未结 7 2091
小鲜肉
小鲜肉 2020-12-16 03:27

Due to my probable misuse of anonymous authentication (see How to prevent Firebase anonymous user token from expiring) I have a lot of anonymous users in my app that I don\'

7条回答
  •  一向
    一向 (楼主)
    2020-12-16 04:13

    I had the same problem. because Firebase doesn't provide any API to delete bulk users but this is how I have deleted all anonymous users.

    Download all the users as json via firebase tool
    firebase auth:export users --format=json
    https://firebase.google.com/docs/cli/auth#file_format

    You can write a firebase cloud function to trigger or write a action method to trigger

    import the json file in to your file,

    const Users = require('./users.json'); // ES5 
    import Users from './users.json'); // ES6

    normally anonymous user doesn't have email so it is easy to delete the record which doesn't have email id

    Users.users.map(user => {
        setTimeout(() => {
          admin.auth().deleteUser(user.localId).then(() =>{
            console.log("Successfully deleted user");
          })
          .catch((error) => {
            console.log("Error deleting user:", error);
          });
        }, 20000);
      });
    

    Don't try to reduce the timeout second if you did you may face error.

    Error deleting user: { Error: www.googleapis.com network timeout. Please try again.
    

提交回复
热议问题