Search code examples
meteoriron-router

Stop Iron-Router from automatically redirecting after login


I noticed, that either my login package or Iron-Router itself redirects you, after logging-in, to the home template. I can't seem to find any way to disable this behavior.

Packages I use, that could be related:

  • iron:router
  • meteorhacks:fast-render
  • useraccounts:materialize
  • routing
  • useraccounts:core
  • accounts-password

I handled the login like this:

unless currentUser
  +login
else
  +yield

Solution

  • Don't try to handle this in your template, instead handle it directly in iron-router with an onBeforeAction handler in your route:

    onBeforeAction: function(){
      if ( Meteor.userId() ){
        this.next();
      } else this.render('login');
    },