Skip to content

Instantly share code, notes, and snippets.

@lidio601
Created January 14, 2020 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lidio601/1640d3b34a65c4c006b3fb87f42face0 to your computer and use it in GitHub Desktop.
Save lidio601/1640d3b34a65c4c006b3fb87f42face0 to your computer and use it in GitHub Desktop.
Google Cloud function to automatically disable new users

Firebase Authentication

Via this Cloud Function you can automatically disable new users.

To deploy this, replace with yours and deploy via command line with:

gcloud functions deploy block-signup --runtime nodejs10 --trigger-event providers/firebase.auth/eventTypes/user.create --trigger-resource <PROJECT-ID>
/**
* @see https://github.com/firebase/firebaseui-web/issues/99
*/
process.env.GCLOUD_PROJECT = '<PROJECT-ID>'
const functions = require('firebase-functions');
const admin = require("firebase-admin");
admin.initializeApp();
exports.blockSignup = functions.auth.user().onCreate(event => {
console.log("event", event);
return admin.auth().updateUser(event.uid, { disabled: true })
.then(userRecord => console.log("Auto blocked user", userRecord.toJSON()))
.catch(error => console.log("Error auto blocking:", error));
});
{
"name": "block-signup",
"version": "1.0.0",
"description": "``` cd functions/block-signup gcloud functions deploy block-signup --runtime nodejs10 --trigger-event providers/firebase.auth/eventTypes/user.create --trigger-resource <PROJECT-ID> ```",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"firebase-admin": "^8.9.0",
"firebase-functions": "^3.3.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment