Skip to content

Instantly share code, notes, and snippets.

@typerory
Created February 8, 2018 17:23
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 typerory/058f2a2148d3b65a3aee27cbcf29d3dd to your computer and use it in GitHub Desktop.
Save typerory/058f2a2148d3b65a3aee27cbcf29d3dd to your computer and use it in GitHub Desktop.
Firebase Cloud Functions Authentication Trigger Writes to Firestore
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