Firebase Authentication disable new users sign up

Newsletter Apr 25, 2022

Use Identity Platform

We must enable Identify Platform in Google Cloud Platform

https://console.cloud.google.com/marketplace/details/google-cloud-platform/customer-identity


Untick Enable create (sign-up)

https://console.cloud.google.com/customer-identity/settings

Use Firebase Functions

We can delete or disable new users by Firebase Functions trigger by onCreate event.

// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
const admin = require("firebase-admin");
admin.initializeApp();
exports.blockSignup = functions
  .auth
  .user()
  .onCreate(user => {
    return new Promise((resolve, reject) => {
      admin
        .firestore()
        .collection('users')
        .doc(user.email)
        .get()
        .then(doc => {
          if (doc.exists) {
            resolve("letUserCreate");
          } else {
            reject(admin.auth().deleteUser(user.uid))
          }
        })
        .catch(reason => {
          console.error(reason)
          reject(admin.auth().deleteUser(user.uid))
        })
    });
  });

Tags