[solved] FlowRouter.go() problems

What i want to do is nothing to fancy, i think:
Redirecting the user after login and logout.

Accounts.onLogin(function () {
    var current = Meteor.user().profile.current;
    Session.set("current", current);
    triggersEnter: [AccountsTemplates.ensureSignedIn],
    action: function(){

What i expected to happen:

  1. after login the user is redirected to “dashboard/someid”
  2. that after clicking a “href=’/logout’’” link the user is redirected to “/”

What actually happens…

  1. after login i’m not redirected at all, but i can see “here1” in console
  2. i’m redirected to “/login” and can see "here2 in console

The awkward thing is, when calling FlowRouter.go("/") or FlowRouter.go("/dashboard/"+Session.get(‘current’));via console it works. When selecting the location bar and pressing enter (reload/f5) it also brings me to the desired location.

What am I doing wrong?


Haven’t tested it myself, but maybe you can try the pattern described in pt 2 in this post:

I am glad someone posted this. For me, this was the most frustrating part of switching to Flow Router. It appears you are using AccountsTemplates to protect routes. In my app I created a global template helper click event that triggers the AccountsTemplates.logout() function. In configuring the useraccounts:flow-routing package, you have to specify what hook to use on logout. Here is what my accounts.js file in my lib directory looks like:

var myPostLogout = function(){
  defaultLayout: 'layout',
  defaultLayoutRegions: {
    header: 'header',
    footer: 'footer'
  defaultContentRegion: 'content',
  onLogoutHook: myPostLogout

That should give you control of the second issue. The article that @vegard posted should help fix the first issue.

@rogerkirkness this really helped me. I additionally missused Meteor.logout() instead of of the appropriate AccountsTemplate function :confused: so the callback wasn’t triggered.

-> so the second problem seems to be solved…

The first one still exists :’(
@vegard I never used coffeescript so i don’t know if i misunderstand sth there, but in my eyes they simply do a

Accounts.onLogin ->
  redirect = Session.get ‘redirectAfterLogin’  if redirect?
    unless redirect is '/login'
      FlowRouter.go redirect

which is just a feature-full version of:

Accounts.onLogin(function () {

so why isn’t this working?


Try this, the part about Routes. https://github.com/meteor-useraccounts/flow-routing

Depending on what styles you are using in your app I would advise using a ready to go template package:

Then all you have to do is include this in the accounts.js file in lib folder: AccountsTemplates.configureRoute(‘signIn’);

I don’t have any Accounts.onLogin in my app.

okay this worked… I simply used the redirect property :confused:
Thx for your efforts

1 Like

Since coffeescript compiles to javascript anyway you can just use a conversion tool.

Just paste this in the output field:

loggedIn = FlowRouter.group
 triggersEnter: [ ->
   unless Meteor.loggingIn() or Meteor.userId()
 route = FlowRouter.current()
 unless route.route.name is 'login'
   Session.set 'redirectAfterLogin', route.path
 FlowRouter.go ‘login’

And this appears in the input field:

var loggedIn;

loggedIn = FlowRouter.group({
  triggersEnter: [
function() {
  var route;
  if (!(Meteor.loggingIn() || Meteor.userId())) {
route = FlowRouter.current();
if (route.route.name !== 'login') {
  Session.set('redirectAfterLogin', route.path);
return FlowRouter.go(‘login’);

but yeah… I don’t like examples in coffeescript either.