Created
September 7, 2014 10:38
-
-
Save ilyador/6dc2d25df5de22d31a79 to your computer and use it in GitHub Desktop.
Custom login method with Meteor
This file contains hidden or 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 loginCallback (error, result) { | |
console.log(error, result); | |
} | |
Meteor.loginWithCode = function(phone, code) { | |
Accounts.callLoginMethod({ | |
methodArguments: [{ | |
hascode: true, | |
phone: phone, | |
code: code | |
}], | |
userCallback: loginCallback | |
}); | |
}; |
This file contains hidden or 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.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 | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in 2018 there was a change to the Meteor accounts_server to look after the stamped token. Just need to return the
userId
now