New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[7397] onLogout should provide connection information #7433
Conversation
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._onLogoutHook.each(function (callback) { | ||
callback(); | ||
callback(logoutContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just call callback({ userId, connection })
here, to provide a defensive copy of the context information to each callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
@Ragsboss In addition to the comments above, how do you feel about having the |
@abernix changing onLogin's current argument would be a breaking change. I'm not sure if this is ok? In fact (as I mentioned in my commit message for first commit), I was wondering if I should instead pass logoutContext as { user, connection } instead of { userId, connection } to make it consistent with existing context (aka attempt in the code) that's passed to onLogin callbacks. As I think more this makes more sense (saving on one user load is too much of a micro optimization and not worth the inconsistency imo). So I changed the code to pass user instead of userId. Take a look and let me know what you think. For reference the onLogin callback receives an object like this based on my tests. |
…ogin argument onLogin argument is an object that has user and connection fields among other fields. So I'm making onLogout also have user and connection fields to make things consistent. Other fields that onLogin callbacks receive include type, allowed, methodName, methodArguments - which are not available or applicable for onLogout.
This depends on meteor/meteor#7433 getting merged and shows the object which will be passed to onLogout on the server when a user logs out.
You're right, we wouldn't want that to be a breaking change. I was mainly rooting for getting the LGTM. |
Magical pull-request gnomes will come through and make sure we're all thinking clearly. Give it some time, but they will come. 🍪 (In seriousness, it will be reviewed by the core team in due time – generally within a week) |
@@ -176,9 +176,10 @@ Ap._failedLogin = function (connection, attempt) { | |||
}); | |||
}; | |||
|
|||
Ap._successfulLogout = function () { | |||
Ap._successfulLogout = function (connection, userId) { | |||
const user = userId && this.users.findOne(userId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we want to always make a database query here? Why wouldn't we just pass userId
and leave to the developer to fetch the user document if they want? I think this is not necessary to do automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Moreover, you are fetching the user object with all fields, which can potentially be large.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to be consistent with other handlers like onLogin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see user
to be passed to onLogin
? connection
is cheap, because it is already available. But user
object is not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onLogin does get an object with user property. See following code. This is also mentioned in the documentation and we indeed use this property in our project.
var user;
if (result.userId)
user = this.users.findOne(result.userId);
var attempt = {
type: result.type || "unknown",
allowed: !! (result.userId && !result.error),
methodName: methodName,
methodArguments: _.toArray(methodArgs)
};
if (result.error)
attempt.error = result.error;
if (user)
attempt.user = user;
Great work @Ragsboss! |
This depends on meteor/meteor#7433 getting merged and shows the object which will be passed to onLogout on the server when a user logs out.
Fix for #7397. See commit description for more details. Added a new test and ran all existing tests.
@abernix could you please review this?