Search code examples
meteoriron-routermeteor-accounts

Using Meteor, useraccounts-core ensureSignedIn plugin won't except '/' route


I am trying to use the ensureSignedIn plugin on all routes except for a front 'home' page that has buttons to login to separate parts of the site.

Here's my route for 'home':

Router.route('/', function () {
  this.render('home');
});

Here's the line for the plugin and exceptions:

Router.plugin('ensureSignedIn', {
  except: ['home', 'atSignIn', 'atSignUp', 'atForgotPassword']
});

Both snippets are from my lib/routes.js file, if that makes a difference. I've tried adding different route names in the except: portion, and they get correctly excepted, but I can't for the life of me get the 'home' route to not show "Must be logged in".

I've googled and read through gitHub issues and haven't seen anyone else with this problem, so it's probably something I'm doing wrong and not a bug with useraccounts or iron-router.


Solution

  • Set the name of the / route to root, then add that route name to the ensureSignedIn settings:

    Router.route('/', {
        name: 'root',
        template: 'home',
        action: function() {
            this.render();
        }
    });
    
    Router.plugin('ensureSignedIn', {
      except: ['root', 'atSignIn', 'atSignUp', 'atForgotPassword', 'atResetPwd']
    });