Skip to content

Instantly share code, notes, and snippets.

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 luiseduardobrito/8455d0efbfd2a1dcd52347cfa3fae0f4 to your computer and use it in GitHub Desktop.
Save luiseduardobrito/8455d0efbfd2a1dcd52347cfa3fae0f4 to your computer and use it in GitHub Desktop.
Accounts Meteor Hack for Linking social accounts (Facebook, Twitter, etc)
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