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

Meteor.userId should not be set in Accounts.onLogout callback #744

Open
davesierra opened this issue Jun 9, 2017 · 4 comments
Open

Meteor.userId should not be set in Accounts.onLogout callback #744

davesierra opened this issue Jun 9, 2017 · 4 comments

Comments

@davesierra
Copy link

davesierra commented Jun 9, 2017

TL;DR

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.

@bolaum
Copy link

bolaum commented Feb 28, 2018

Did you solve this?

@bolaum
Copy link

bolaum commented Feb 28, 2018

I ended up using Meteor.user() instead of Meteor.userId in the / route test.

@davesierra
Copy link
Author

@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.

@japrogramer
Copy link

if neither is defined how would we know which user is logging out ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants