Accounts.onLogin callback fired twice?

Hello,

I have this in my server code:

Accounts.onLogin(function() {
console.log(Meteor.user().emails[0].address);
});

Sometimes (for example when I log in from the client), the callback is fired once as expected:

I20151014-17:34:40.342(2)? izumi@cat.cc

But sometimes (for example when I’m logged in already and the server is restarted after the code is changed), the callback is fired twice:

I20151014-17:27:02.192(2)? izumi@cat.cc
I20151014-17:27:16.905(2)? izumi@cat.cc

Is this normal? Why is it happening?

Thanks in advance!

I figured it out. When the code changes, the client reloads. So two things happen. First, the server logs back the current user when it restarts, but since the client is also refreshed, a logout + login is triggered from the client (same as closing and reopening the tab). That’s why we see two logins.

2 Likes