问题描述
在我注册特定用户后,有什么方法可以阻止更多用户注册 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 上注册新用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!