Created
July 30, 2014 21:29
-
-
Save resure/6932ca976ad47595e801 to your computer and use it in GitHub Desktop.
Meteor External Auth
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
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