如何防止新用户在 Firebase 上注册? [英] How to prevent new user registration on Firebase?

查看:27
本文介绍了如何防止新用户在 Firebase 上注册?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我注册了特定用户后,有什么方法可以阻止更多用户注册 Firebase?例如,如果我只希望注册 10 个特定用户而不希望更多,有没有办法关闭以后的注册?

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?

推荐答案

经过一番挖掘,虽然文档中没有正式列出此方法,但我发现您可以自动删除任何已创建的新用户,一旦他们签名使用 Cloud Functions 和管理 SDK.这是我用来在新用户尝试注册时删除他们的代码:

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);
    });
  });

更新:Firebase 还引入了撤销令牌 API.这很重要的原因是因为当用户注册时,即使他们被立即删除,他们也会获得一个有效的令牌,该令牌至少可以保持几分钟的身份验证,如果不是更长的话.考虑使用以下方法在删除后立即撤销用户的令牌:

Update: Firebase has introduced a revoke token API as well. The reason this is important is because when a user registers, even if they are immediately deleted, they are issued a valid token that remains authenticated for at least several minutes, if not longer. Consider revoking the user's token immediately after deletion by utilizing:

admin.auth().revokeRefreshTokens(uid)
  .then(() => {
    return admin.auth().getUser(uid);
})

这篇关于如何防止新用户在 Firebase 上注册?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆