Last active
June 23, 2020 17:49
-
-
Save richardcalahan/0f1505abd703a4f0a2a72be056a09d52 to your computer and use it in GitHub Desktop.
userCreateProps
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
exports.userCreateProps = functions.auth.user().onCreate( (user) => { | |
const props = {}; | |
props["email"] = user.email; | |
if ( user.displayName ) { | |
props["displayName"] = user.displayName; | |
} | |
if ( user.phoneNumber ) { | |
props["phoneNumber"] = user.phoneNumber; | |
} | |
if (user.photoUrl) { | |
props["photoUrl"] = user.photoUrl; | |
} | |
var isUpdatePhoto = false; | |
user.providerData.forEach((profile) => { | |
if (profile.providerId === "facebook.com") { | |
props["facebookId"] = profile.uid; | |
const photoURL = "https://graph.facebook.com/" + profile.uid + "/picture?width=240"; | |
props["photoUrl"] = photoURL; | |
isUpdatePhoto = true | |
//return true | |
} | |
// console.log("Sign-in provider: " + profile.providerId); | |
// console.log(" Provider-specific UID: " + profile.uid); | |
// console.log(" Name: " + profile.displayName); | |
// console.log(" Email: " + profile.email); | |
// console.log(" Photo URL: " + profile.photoURL); | |
}); | |
admin.auth().updateUser(user.uid, { photoURL: props["photoUrl"] }); | |
return admin.database().ref("users/" + user.uid).update(props); | |
}); |
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
exports.userCreateProps = functions.auth.user().onCreate( (user) => { | |
const props = {}; | |
props["email"] = user.email; // The email of the user. | |
props["displayName"] = user.displayName; // The display name of the user. | |
props["photoUrl"] = user.photoURL; | |
props["phoneNumber"] = user.phoneNumber; | |
if (user.phoneNumber) { | |
props["phoneNumber"] = user.phoneNumber;// The display name of the user. | |
} | |
if (user.photoUrl) { | |
props["photoUrl"] = user.photoUrl;// The display name of the user. | |
} | |
var isUpdatePhoto = false; | |
user.providerData.forEach((profile) => { | |
if (profile.providerId === "facebook.com") { | |
props["facebookId"] = profile.uid; | |
const photoURL = "https://graph.facebook.com/" + profile.uid + "/picture?width=240"; | |
props["photoUrl"] = photoURL; | |
isUpdatePhoto = true | |
//return true | |
} | |
// console.log("Sign-in provider: " + profile.providerId); | |
// console.log(" Provider-specific UID: " + profile.uid); | |
// console.log(" Name: " + profile.displayName); | |
// console.log(" Email: " + profile.email); | |
// console.log(" Photo URL: " + profile.photoURL); | |
}); | |
admin.auth().updateUser(user.uid, { photoURL: props["photoUrl"] }); | |
return admin.database().ref("users/" + user.uid).update(props); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment