mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
[7397] onLogout should provide connection information
Adding an argument to onLogoutCallback. The callback is an object with two properties - userId and connection. I thought of loading up the user and instead have the user property, but felt like this maybe redundant. Logout hooks can always do this if they need. However one advantage of having user instead of userId is it makes it symmetric/consistent with onLogin callback. Let me know if you strongly feel we should have user instead userId.. Also extended an existing test to validate the onLogout callback gets this argument with expected user id
This commit is contained in:
@@ -176,9 +176,10 @@ Ap._failedLogin = function (connection, attempt) {
|
||||
});
|
||||
};
|
||||
|
||||
Ap._successfulLogout = function () {
|
||||
Ap._successfulLogout = function (connection, userId) {
|
||||
var logoutContext = { userId: userId, connection: connection };
|
||||
this._onLogoutHook.each(function (callback) {
|
||||
callback();
|
||||
callback(logoutContext);
|
||||
return true;
|
||||
});
|
||||
};
|
||||
@@ -537,8 +538,8 @@ Ap._initServerMethods = function () {
|
||||
accounts._setLoginToken(this.userId, this.connection, null);
|
||||
if (token && this.userId)
|
||||
accounts.destroyToken(this.userId, token);
|
||||
accounts._successfulLogout(this.connection, this.userId);
|
||||
this.setUserId(null);
|
||||
accounts._successfulLogout();
|
||||
};
|
||||
|
||||
// Delete all the current user's tokens and close all open connections logged
|
||||
|
||||
@@ -388,6 +388,9 @@ Tinytest.add(
|
||||
var onLoginStopper = Accounts.onLogin(function(attempt) {
|
||||
test.equal(Meteor.userId(), onLoginExpectedUserId, "onLogin");
|
||||
});
|
||||
var onLogoutStopper = Accounts.onLogout(function(logoutContext) {
|
||||
test.equal(logoutContext.userId, onLogoutExpectedUserId, "onLogout");
|
||||
});
|
||||
var onLoginFailureStopper = Accounts.onLoginFailure(function(attempt) {
|
||||
test.equal(Meteor.userId(), onLoginFailureExpectedUserId, "onLoginFailure");
|
||||
});
|
||||
@@ -408,9 +411,14 @@ Tinytest.add(
|
||||
var onLoginFailureExpectedUserId = userId;
|
||||
test.throws(function() { conn.call('login', { resume: "bogus" }) }, '403');
|
||||
|
||||
// Trigger onLogout callbacks
|
||||
var onLogoutExpectedUserId = userId;
|
||||
conn.call('logout');
|
||||
|
||||
conn.disconnect();
|
||||
validateStopper.stop();
|
||||
onLoginStopper.stop();
|
||||
onLogoutStopper.stop();
|
||||
onLoginFailureStopper.stop();
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user