Skip to content
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

Merged
merged 2 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/accounts-base/accounts_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,22 @@ export class AccountsClient extends AccountsCommon {
this._pageLoadLoginCallbacks.forEach(callback => callback(attemptInfo));
this._pageLoadLoginCallbacks = [];
this._pageLoadLoginAttemptInfo = attemptInfo;
};
}

// _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(callback) {
// Are we already logged in?
if (this.connection._userId) {
// If already logged in before handler is registered, it's safe to
// assume type is a 'resume', so we execute the callback at the end
// of the queue so that Meteor.startup can complete before any
// embedded onLogin callbacks would execute.
Meteor.setTimeout(() => callback({ type: 'resume' }), 0);
}
}

///
/// LOGIN TOKENS
Expand Down
8 changes: 7 additions & 1 deletion packages/accounts-base/accounts_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ export class AccountsCommon {
* as user details, connection information, etc.
*/
onLogin(func) {
return this._onLoginHook.register(func);
let ret = this._onLoginHook.register(func);
// call the just registered callback if already logged in
this._startupCallback(ret.callback);
return ret;
}

/**
Expand Down Expand Up @@ -285,6 +288,9 @@ export class AccountsCommon {
}
return new Date() > (new Date(when) - minLifetimeMs);
}

// No-op on the server, overridden on the client.
_startupCallback(callback) {}
}

// Note that Accounts is defined separately in accounts_client.js and
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts-base/package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
summary: "A user account system",
version: "1.4.4",
version: "1.4.5",
});

Package.onUse(api => {
Expand Down
1 change: 1 addition & 0 deletions packages/callback-hook/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class Hook {
this.callbacks[id] = callback;

return {
callback,
stop: () => {
delete this.callbacks[id];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/callback-hook/package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
summary: "Register callbacks on a hook",
version: '1.1.0'
version: '1.2.0'
});

Package.onUse(function (api) {
Expand Down