I am trying to get the login process to work. basically, all routes should get redirected to "/login" if the user is not logged in. All except "/signup" and "/reset", because you obviously wont be logged in if you go there.
Router.configure({
layoutTemplate: 'layout'
});
Router.onBeforeAction(function () {
except: ['signup','reset']
if (!Meteor.userId()) {
// if the user is not logged in, render the Login template
this.render('login');
}
else {
this.next();
}
});
Router.route('/', function (){
this.render('app-main-page');
});
Router.route('/signup', function () {
this.render('signup');},
{
name:'signup'
});
Router.route('/reset', function () {
this.render('reset');},
{
name:'reset'
});
// and a bunch of more routes within the app
});
In general the onBeforeAction is working, when someone is not logged in the login template is rendered. However, the "except" part is not working, which means users cannot sign up since they get redirected to a login page. Does anyone have any insights? it seems like an extremely simple piece of code, I have absolutely no idea where I could have made an error.
use
this,nexr()
to leave fromonBeforeAction
,