Question

I'm trying to secure my meteor app with iron-router, here's my onBeforeAction function:

this.route('manageUsers', {
    path: '/panel/user_management', 
    layoutTemplate: 'panel',
    onBeforeAction: function(){
        if((Meteor.user() === null)||(Meteor.user().role !== 'superAdmin')){
            Router.go('signIn');
            throwAlert('You dont have access to see this page', 'notification');
        }
    }
});

When I'm trying to go to /panel/user_management subpage by pressing a link button everything goes fine (user is redirected etc.), but when I type the path directly in my browser (localhost:3000/panel/user_management) and hit enter user is not getting redirected and I receive in console Exception in defer callback error. Anyone know what I'm doing wrong?

For additional information, this view lists me all users registered. When I go to this path normally (without error) I see complete user list. When I receive error template doesn't appear in > yield.

Was it helpful?

Solution

Finally, I've solved this - the problem was wrong if statement, here's the correct one:

if((!Meteor.user())||(Meteor.user().role !== 'superAdmin')){}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top