Ways to stop new users from registering on Firebase?

Can I restrict the number of users signing up on Firebase after a specific number has been reached? For example, if I have already signed up 10 particular users and do not want any more signups, is there a way to prevent future registrations?

Answer №1

Through thorough investigation, I uncovered a method that is not officially documented but allows for the automatic deletion of new users immediately after they sign up using Cloud Functions and the admin SDK. Below is the code I utilized to ensure that any new user attempting to sign up is promptly deleted:

  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: Additionally, Firebase now offers a revoke token API. This update is crucial because even if a user is deleted immediately upon registration, they are still given a valid token that remains authenticated for a period of time. To address this issue, consider revoking the user's token right after deletion by implementing the following:

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

Answer №2

If you've come across this post on or after 3/21/21, Firebase has introduced a new feature that allows users to disable user creation and deletion directly on the Identity platform page.

For more information, please visit https://github.com/firebase/firebaseui-web/issues/99#issuecomment-794537000

You no longer have to create an API for managing user authentication in order to control user creation and deletion processes.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React has reached the maximum update depth limit

In my current project, I am developing a react application that involves a user inputting a search term and receiving an array of JSON data from the backend. On the results page, I have been working on implementing faceted search, which includes several fi ...

The image being displayed is significantly wider than the corresponding HTML element

I'm attempting to display this webpage in PNG format using npm's wkhtmltox: <!doctype html> <html> <head> <meta charset="utf-8"> <style> html, body { padding: 0; width: 340px; } ...

What methods does Google use to display its search results on the search engine results page?

Upon first observation, I realized that the search results were not present in the HTML received from the server. To investigate further, I turned to Dev Tools and examined the additional files downloaded by my browser. I discovered that there was only on ...

What is the best way to showcase multiple selected values in a div using jQuery?

Is there a way to use jquery to populate an empty div with the values selected from a multi-select dropdown? How can I achieve this in the context of the provided code snippet? <select multiple data-style="bg-white rounded-pill px-4 py-3 shadow-sm" c ...

Encountering a ReferenceError in Angular 4 due to d3 not being defined when importing in a module

I'm looking to incorporate these imports into my angular 4 app.module, rather than adding them directly to my index file. In app.module.ts -> import d3 from "d3"; console.log(d3) // Confirming successful import of D3 import nvd3 from "nvd3"; H ...

Retrieve an array from the updated scope

I need help with my code. How can I retrieve the names from an array and display them in my input box? Also, how do I get all the changed names back into the array? Thanks in advance! - Marco app.js var g[]; var names = ['John', 'Steve&apo ...

Is it possible to utilize the Vuejs router routes array to dynamically generate a navigation menu?

Below is the code I am using to set up VueJS routes and pass them into a router: export const routesArray = { routes: [ { path: '/', name: 'Add Stash', component: Form }, { path: '/log', ...

Struggling to find the width of an SVG text box or add line breaks after a specific number of characters?

I am currently working on creating an SVG text box using the amazing Raphael library. The content inside this text box comes from a dynamic string that is extracted from an XML document. There are times when this string turns out to be longer than the can ...

Organize Development and Production files in npm or webpack for improved efficiency

In React Native projects, we typically use index.android.js and index.ios.js to differentiate between the same file for Android and iOS platforms. But I wonder if it's possible to separate files based on the development and production environments as ...

Streaming video between web browsers using WebRTC and CORS

The demo of WebRTC (https://webrtc.github.io/samples/src/content/capture/video-video) showcases the ability to stream one video's contents to another using video.captureStream(). However, I'm encountering issues when attempting this across differ ...

Programmatically link validation rules to form fields

I have implemented validation in a form using VeeValidate with Vue.js. Each input displays an error message related to the specific field where the error occurred. <div class="input-group"> <input type="date" class= ...

Struggling to populate dropdown values from LocalStorage

I have saved information from an HTML form to the local storage. However, when I retrieve the data from local storage to populate the form for editing, the data appears in input text fields as expected but not in dropdowns or checkboxes. How can I ensure ...

Tips for comparing props in the ComponentDidUpdate method when dealing with a complex data structure that is connected to Redux

I have been experimenting with the new lifecycles of React v16. It works perfectly fine when comparing single keys. However, when dealing with large data structures like Arrays of objects, performing deep comparison can be quite expensive. My specific sce ...

Retrieving JSON information from asynchronous JavaScript and XML (AJAX)

I am struggling with making a URL that contains JSON Data work properly. The issue lies in the data field - I am unsure of what to input here as it is currently undefined. My goal is to store an array of the JSON data received from the ajax request. What ...

It is advisable to keep extra information in req.params for better practice

As I work on developing a RESTful API for my web application, I have discovered a helpful practice. When creating various routes and implementing the logic for each one, I found it beneficial to store any additional data needed in the req object under the ...

Add up unique values in MongoDB

Document layout { "_id": "5a21c5dff772de0555480ef5", "date": "2017-10-06T00:00:00.000Z", "amount": 1, "location": "Canada", "__v": 0 } I am looking to calculate the total amount for each location and presen ...

Can I set my target SDK to Android 28 (e.g. `targetSdkVersion 28`) while still integrating both appcompat-v7 and Firebase into my app

Has anyone successfully set targetSdkVersion 28 for Android and used Firebase? Here's an example of my build.gradle configuration: apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { appli ...

What is the best way to prevent a directory from being included in the Webpack bundle?

Issue: Despite configuring my Webpack settings in webpack.config.js to exclude files from the ./src/Portfolio directory, all files are being bundled by Webpack. Code Snippet: Webpack.config.js const path = require('path'); module.exports = { ...

"Creating a 3D rotation effect on individual objects nested within other objects using Javascript

In my software, I've created four Physijs.BoxMesh(...) shapes, all nested within an independent object. My goal is to rotate these four physics boxes as a whole, but once they are grouped under the 5th object, they no longer respond to rotation comman ...

Retrieving the initial element within a JSON structure

Let's dive right in. I am receiving a JSON object that contains another object within it, like this: function getSummonerInfo(summonerName, region) { LolApi.Summoner.getByName(summonerName, region, function(err, summoner) { if(!err) { ...