Permalink
Browse files

Preserve `this` for login handlers when run from a method.

Also rename `Accounts.createToken` to `Accounts._runLoginHandlers`. For
consistency we should probably also have `Accounts.destroyToken` be
something like `Accounts._destroyLoginToken`, but I'm not going to
change that now because it's already shipped.
  • Loading branch information...
1 parent 36ff205 commit bed799f240325282a7a0506c2aed1ea0e3566065 Emily Stark committed Jan 30, 2014
Showing with 9 additions and 9 deletions.
  1. +9 −9 packages/accounts-base/accounts_server.js
@@ -51,23 +51,23 @@ Accounts.registerLoginHandler = function(handler) {
loginHandlers = [];
-// Checks a user's credentials against all the registered login handlers, and
-// returns a newly created login token if the credentials are valid. It is like
-// the login method, except that it doesn't set the logged-in user on the
-// connection. Throws a Meteor.Error if logging in fails, including the case
-// where none of the login handlers handled the login request. Otherwise, returns
-// {id: userId, token: *, tokenExpires: *}.
+// Checks a user's credentials against all the registered login
+// handlers, and returns a login token if the credentials are valid. It
+// is like the login method, except that it doesn't set the logged-in
+// user on the connection. Throws a Meteor.Error if logging in fails,
+// including the case where none of the login handlers handled the login
+// request. Otherwise, returns {id: userId, token: *, tokenExpires: *}.
//
// For example, if you want to login with a plaintext password, `options` could be
// { user: { username: <username> }, password: <password> }, or
// { user: { email: <email> }, password: <password> }.
-Accounts.createToken = function (options) {
+Accounts._runLoginHandlers = function (options) {
// Try all of the registered login handlers until one of them doesn't return
// `undefined`, meaning it handled this call to `login`. Return that return
// value, which ought to be a {id/token} pair.
for (var i = 0; i < loginHandlers.length; ++i) {
var handler = loginHandlers[i];
- var result = handler(options);
+ var result = handler.apply(this, [options]);
if (result !== undefined)
return result;
}
@@ -108,7 +108,7 @@ Meteor.methods({
// Login handlers should really also check whatever field they look at in
// options, but we don't enforce it.
check(options, Object);
- var result = Accounts.createToken(options);
+ var result = Accounts._runLoginHandlers.apply(this, [options]);
if (result !== null) {
// This order (and the avoidance of yields) is important to make
// sure that when publish functions are rerun, they see a

0 comments on commit bed799f

Please sign in to comment.