Skip to content

Instantly share code, notes, and snippets.

@ilyador
Created September 7, 2014 10:38
Show Gist options
  • Save ilyador/6dc2d25df5de22d31a79 to your computer and use it in GitHub Desktop.
Save ilyador/6dc2d25df5de22d31a79 to your computer and use it in GitHub Desktop.
Custom login method with Meteor
function loginCallback (error, result) {
console.log(error, result);
}
Meteor.loginWithCode = function(phone, code) {
Accounts.callLoginMethod({
methodArguments: [{
hascode: true,
phone: phone,
code: code
}],
userCallback: loginCallback
});
};
Accounts.registerLoginHandler('login', function(loginRequest) {
var user = Meteor.users.findOne({phone: loginRequest.phone});
if(user.code !== loginRequest.code) {
return null;
}
var stampedToken = Accounts._generateStampedLoginToken();
var hashStampedToken = Accounts._hashStampedToken(stampedToken);
Meteor.users.update(user._id,
{$push: {'services.resume.loginTokens': hashStampedToken}}
);
return {
userId: user._id,
token: stampedToken.token
};
});
@mikkelking
Copy link

in 2018 there was a change to the Meteor accounts_server to look after the stamped token. Just need to return the userId now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment