Skip to content

Instantly share code, notes, and snippets.

@marcusx2
Last active March 17, 2021 15:30
Show Gist options
  • Save marcusx2/9b927a46a397f6e181bd2eb3ab0718d8 to your computer and use it in GitHub Desktop.
Save marcusx2/9b927a46a397f6e181bd2eb3ab0718d8 to your computer and use it in GitHub Desktop.
cloud function block create
//only allow to sign up if the user exists on firestore.
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))
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment