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

查看:78
本文介绍了如何防止在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和admin 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天全站免登陆