How to prevent new user registration on Firebase?

社会主义新天地 提交于 2019-12-20 04:38:49

问题


Is there any way to turn off more users from signing up on Firebase after I've signed up specific users? For instance, if I only want 10 particular users to be signed up and no more, is there a way to turn off future signups?


回答1:


After some digging, even though this method isn't officially listed in the documentation, I found that you can automatically delete any new user that's created once they have signed up using Cloud Functions and the admin SDK. Here's the code I used to delete any new user the moment they have tried signing up:

  exports.deleteNewUser = functions.auth.user().onCreate((event) => {
  const uid = event.data.uid; // The Firebase user.
  admin.auth().deleteUser(uid)
    .then(function() {
      console.log("Successfully deleted user");
    })
    .catch(function(error) {
      console.log("Error deleting user:", error);
    });
  });


来源:https://stackoverflow.com/questions/49162111/how-to-prevent-new-user-registration-on-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!