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
[fix #10157] Make sure onLogin callbacks are called during startup #10543
[fix #10157] Make sure onLogin callbacks are called during startup #10543
Conversation
@benjamn , I was just checking where my changes were in the Meteor repo and I could not find them. Should I have built this PR off the 1.8.2 branch originally? I noticed it was still not merged in and that I was required to push my changes back to my repo, just did it. |
@brucejo75 we've experienced the same issue and went around it by doing the following: if (Meteor.user()) { Accounts.onLogin(callback); I think your approach is similar, but why not just "fix" the onLogin callback (I can't imagine a scenario where someone would not want to have that callback executed when the user is, by chance, logged in before AccountsCommon is constructed. |
Hi @KoenLav, I am trying to parse your issue:
Are you saying that I should not distinguish between client or server and simply make the callback if the user is logged in (client or server)? On the client side there is an explicit login during On the server side I do not see anything like that. Plus the Given this information I thought it was prudent to only implement the client side. I have not seen a bug where this is an issue. Is it something you have encountered? |
@brucejo75 I don't think this issue occurs on the server either, maybe I didn't explain properly. What I meant with fixing the login callback would be: if the user is already logged in when adding a loggedIn callback, it should probably fire right away (currently this doesn't happen, which, in my opinion, is the issue). |
@KoenLav , That is why I was confused because that is exactly what my changes do. This function is called right after the callback is registered: // _startupCallback executes on onLogin callbacks
// at registration time if already logged in
// this can happen when new AccountsClient is created
// before callbacks are registered see #10157
_startupCallback(callbackId) {
// Are we already logged in?
if(this.connection._userId) {
// then go ahead and call the callback that we just registered
let cb = this._onLoginHook.callbacks[callbackId];
// if already logged in before handler is registered
// safe to assume that type is a 'resume'
// execute the callback at the end of the queue so that
// Meteor.startup can complete before any embedded onLogin
// callbacks would execute
Meteor.setTimeout(() => cb({loginDetails: {type: 'resume'}}), 0);
}
} When I make the callback (via a I might make the case that all callback should defer until all |
Apologies, I thought you added a new method which produced the expected behavior, rather than improved the existing onLogin method. |
Sorry I haven't had a chance to follow up on this properly. For what it's worth, this is definitely on the list of changes we plan to ship with Meteor 1.8.2. I think I want to incorporate this functionality into the If that makes sense and you have time, feel free to give it a go. Otherwise I can make those changes after #10585 is finished and merged into |
@benjamn, I will not get a chance to look at it closely for 2 weeks, deadline and out of office. I quickly glanced at it:
|
@benjamn, I took a closer look at the
When registering the callback, I can detect that the ProposalAdd an optional argument to the
Let me know if that is what you were thinking. I can get a PR pulled together. |
Hi @benjamn I was thinking about this some more and thought that I might be able to save the I do not think this would work, because the Hook class is defined pretty liberally. And the caller could call Given this information, I think that handing arguments back to the register call is a bad idea too. The But then to use this capability it in the example of the accounts package would require making the I am not sure that adding this capability to the Recommend taking this PR as an accounts package feature. |
4151c4d
to
6c3ce7b
Compare
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.
Finally getting this in—sorry for the long wait @brucejo75.
This repairs a timing issue. #10157
Essentially, the user is logged in before any
onLogin
callbacks can be set up. To remedy the problem:I added a new internal function.
AccountsCommon#_startupCallback
internal function_startupCallback
is called is called right after anonLogin
callback is registered._startupCallback
checks if the user is logged in (non reactively), if true then the newly registeredcallback
is scheduled to execute at the back of the event loop. This makes sure that all necessaryMeteor.startup
callbacks complete before theonLogin
callback executes if theonLogin
is called within aMeteor.startup
.