meteor-useraccounts / flow-routing

Useraccounts packages add-on for integration with Flow Router and Blaze Layout.
https://atmospherejs.com/useraccounts/flow-routing
MIT License
72 stars 50 forks source link

Can't login after logout and redirect #27

Open joarobles opened 8 years ago

joarobles commented 8 years ago

I have the following configuration for useraccounts:

AccountsTemplates.configure({
  defaultLayout: 'baseLayout',
  defaultLayoutRegions: {},
  defaultContentRegion: 'content',
  defaultState: 'signUp',
  confirmPassword: false,
  onLogoutHook: function () {
    FlowRouter.go('atSignIn');
  },
});

And this is my flow route for handling logout:

FlowRouter.route('/logout', {
  action: AccountsTemplates.logout
});

The problem is that, whenever I log out I get redirected to the sign in view (as expected) but I won't be able to login again: when I enter the right credentials no errors are shown but the form won't dissapear. Any idea?

mbernath commented 8 years ago

I can confirm this problem exists.

I added a triggers.enter logger and found, that after sign-in the user is randomly getting redirected to /logout again. If I try for 5-10 times, I am getting redirected to my homeRoutePath.

mbernath commented 8 years ago

I found the cause of the problem: The flow-routing always stores the previous Route so that when ensureSignedIn sends a user back to sign-in, he can then be redirected to the previous page. That totally makes sense.

This just doesn't work if there is a route, which causes the user to be logged out. Then the previous route is "logout".

But this can easily be fixed:

Just name your logout route "logout" and add it to the "knownRoutes" like this:

AccountsTemplates.knownRoutes.push('logout');

That causes flow-routing to not remember the previous route. Then everything works as expected.

joarobles commented 8 years ago

Yeah, that will do the trick! Thanks Marc!

DanielDornhardt commented 8 years ago

Thanks @mbernath - life saver - should go to the docs!

garyebersole commented 8 years ago

@mbernath Thanks!! Chased this for hours while refactoring my app to replace my own accounts system with useraccounts. Your solution saved me from falling back to my own mediocre implementation for user account management.

stinghz commented 8 years ago

AccountsTemplates.knownRoutes.push('logout'); That causes flow-routing to not remember the previous route.

Thanks @mbernath