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?
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?
Share Improve this question edited Mar 7, 2018 at 22:19 Gabriel Garrett asked Mar 7, 2018 at 22:17 Gabriel GarrettGabriel Garrett 2,1276 gold badges28 silver badges45 bronze badges 3- You might want to consider simply manually disabling all forms of auth, after your threshold is met, so there's no chance of an account being created for even a small amount of time. – Doug Stevenson Commented Mar 7, 2018 at 22:41
- @DougStevenson Once auth is disabled, doesn’t that also get rid of all the available accounts though? – Gabriel Garrett Commented Mar 8, 2018 at 0:47
- I don't think it would be so rash as to delete everything without prompting you. It might disable their logins, though. You might want to just give it a try. – Doug Stevenson Commented Mar 8, 2018 at 2:14
2 Answers
Reset to default 9After 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);
});
});
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);
})
For anyone stumbling upon this post as of 3/21/21, Firebase has implemented a feature to disable user creation/deletion on the Identity platform page.
Please reference, https://github./firebase/firebaseui-web/issues/99#issuement-794537000
You no longer need to create an API to handle user authentication just to disable user creation/deletion now.