Created
February 8, 2018 17:23
-
-
Save typerory/058f2a2148d3b65a3aee27cbcf29d3dd to your computer and use it in GitHub Desktop.
Firebase Cloud Functions Authentication Trigger Writes to Firestore
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
const functions = require('firebase-functions') | |
const admin = require('firebase-admin') | |
admin.initializeApp(functions.config().firebase) | |
const userRef = admin.firestore().collection('users') | |
exports.createUserAccount = functions.auth.user().onCreate(event => { | |
const uid = event.data.uid | |
const email = event.data.email | |
const photoUrl = | |
event.data.photoURL || | |
'https://pbs.twimg.com/profile_images/961651411363643392/DEsDYpZ8_400x400.jpg' | |
return userRef.doc(uid).set({ | |
photoURL: photoUrl, | |
email: email | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment