You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Meteor.userId() should not exist in the callback of Accounts.onLogout()
Issue
If the following holds true:
AccountsCommon#userId()
Get the current user id, or null if no user is logged in. A reactive data source.
Then it doesn't make sense that on the Accounts.onLogout() callback, Meteor.userId() exists yet Meteor.user() does not.
Example
I have the following code:
Accounts.onLogout( () => {
console.log('accounts onlogout userId', Meteor.userId()); //=> '54hads572' (bad)
console.log('accounts onlogout userId', Meteor.user()); //=> undefined (good)
//end session code;
FlowRouter.go('/'); //redirect user to / so they can sign back in
});
// and in routes.js
FlowRouter.route('/', {
name: 'signIn',
triggersEnter: [],
action: function(params, queryParams) {
// it will arrive here with a Meteor.userId, and try to redirect back to /dashboard
if ( !Meteor.userId() ) {
mount(SignIn);
} else {
FlowRouter.go('/dashboard');
}
}
});
So if I log out, either via clearing my loginTokens on the DB or through the 'Sign Out' button provided by Accounts, it will redirect me back to /dashboard thinking I was logged in.
The text was updated successfully, but these errors were encountered:
@bolaum Yep, that was my solution as well. The reason I opened this issue was that it's a bit misleading if someone were to use Meteor.userId, it caused alot of confusion and too much time spent digging around to realize this subtle difference.
TL;DR
Meteor.userId() should not exist in the callback of Accounts.onLogout()
Issue
If the following holds true:
AccountsCommon#userId()
Then it doesn't make sense that on the Accounts.onLogout() callback, Meteor.userId() exists yet Meteor.user() does not.
Example
I have the following code:
So if I log out, either via clearing my loginTokens on the DB or through the 'Sign Out' button provided by Accounts, it will redirect me back to /dashboard thinking I was logged in.
The text was updated successfully, but these errors were encountered: