Skip to content

Instantly share code, notes, and snippets.

@resure
Created July 30, 2014 21:29
Show Gist options
  • Save resure/6932ca976ad47595e801 to your computer and use it in GitHub Desktop.
Save resure/6932ca976ad47595e801 to your computer and use it in GitHub Desktop.
Meteor External Auth
function centerAuth(loginRequest) {
var response = HTTP.call('POST', 'http://localhost:4567/auth',
{params: {username: loginRequest.username, password: loginRequest.password}});
response = JSON.parse(response.content);
if (response && response.response === 'ok') {
var userId = null;
var user = Meteor.users.findOne({ username: loginRequest.username });
if (! user) {
userId = Meteor.users.insert({ username: loginRequest.username });
} else {
userId = user._id;
}
return {userId: userId};
}
}
Accounts.registerLoginHandler(centerAuth);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment