Last active
June 19, 2017 15:09
-
-
Save mackbrowne/30317eba75d13683566ead357b52bbce to your computer and use it in GitHub Desktop.
Accounts Meteor Link Hack
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; | |
}); |
Put in Server code
Make sure all email verification is mandatory on all accounts
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/a/18382093/2136249
^^ original