Skip to content

Instantly share code, notes, and snippets.

@azzeddineCH
Last active July 17, 2017 15:10
Show Gist options
  • Select an option

  • Save azzeddineCH/333965612f7f768ad74902be8ece935f to your computer and use it in GitHub Desktop.

Select an option

Save azzeddineCH/333965612f7f768ad74902be8ece935f to your computer and use it in GitHub Desktop.
var functions = require('firebase-functions');
var admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.createUserAccount = functions.auth.user().onCreate(event => {
const email = event.data.email;
const uid = event.data.uid;
const photoURL = event.data.photoURL || "";
var username = event.data.displayName;
/**
* if the username is null we use the fist part of his email
* as the the default username
*/
if (username == null) {
username = email.split("@")[0];
}
return admin.database().ref("/users").child(uid).set({
email,
username,
photoURL
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment