Last active
March 17, 2021 15:30
-
-
Save marcusx2/9b927a46a397f6e181bd2eb3ab0718d8 to your computer and use it in GitHub Desktop.
cloud function block create
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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