Last active
July 17, 2017 15:10
-
-
Save azzeddineCH/333965612f7f768ad74902be8ece935f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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