Forked from mackbrowne/gist:30317eba75d13683566ead357b52bbce
Last active
June 19, 2017 15:09
-
-
Save luiseduardobrito/8455d0efbfd2a1dcd52347cfa3fae0f4 to your computer and use it in GitHub Desktop.
Accounts Meteor Hack for Linking social accounts (Facebook, Twitter, etc)
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
Accounts.onCreateUser((options, user) => { | |
user.city = null; | |
user.networks = []; | |
user.attending = []; | |
if (user.profile == null) { | |
user.profile = {}; | |
} | |
if (user.services != null) { | |
var service = _.keys(user.services)[0]; | |
var email = user.services[service].email; | |
if (email != null) { | |
var oldUser = Meteor.users.findOne({ | |
"emails.address": email | |
}); | |
if (oldUser != null) { | |
if (oldUser.services == null) { | |
oldUser.services = {}; | |
} | |
if (service === "google" || service === "facebook" || service === "twitter") { | |
oldUser.services[service] = user.services[service]; | |
Meteor.users.remove(oldUser._id); | |
user = oldUser; | |
} | |
} else { | |
if (service === "google" || service === "facebook" || service === "twitter") { | |
if (user.services[service].email != null) { | |
user.emails = [{ | |
address: user.services[service].email, | |
verified: true | |
}]; | |
} else { | |
throw new Meteor.Error(500, service + " account has no email attached"); | |
} | |
user.profile.name = user.services[service].name; | |
} | |
} | |
} | |
} | |
return user; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment