Reputation: 4376
I have a page that I want the user to not be able to access unless they have a certain property. I have defined a filter as such:
Meteor.Router.filters({ //line 24
isX: function(page) {
if(Roles.userIsInRole(this.userId, ['X'])) {
return page;
} else {
return '/error';
}
}
});
Meteor.Router.filter(isX, {only : 'xPage'});
this code exists in my router.js file. When I try to compile it I get the following error:
\.meteor\packages\meteor-tool\1.1.4\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:245 throw(ex); ^ TypeError: Cannot call method 'filters' of undefined at app\lib\router.js:24:15 at app\lib\router.js:70:3 //end of file at \.meteor\local\build\programs\server\boot.js:222:10 at Array.forEach (native) at Function._.each._.forEach (\.meteor\packages\meteor-tool\1.1.4\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11) at \.meteor\local\build\programs\server\boot.js:117:5 Exited with code: 8 Your application is crashing. Waiting for file change.
I'm at a loss because this is pretty much straight out of the examples for iron router.
Upvotes: 0
Views: 103
Reputation: 681
I'm not sure where you are getting Meteor.Router.filters
with regards to iron:router
. You can do something very similar to what you need with an onBeforeAction
though.
var isX = function() {
if (Roles.userIsInRole(this.userId, ["X"])) {
this.next();
}
else {
this.redirect("/error");
}
};
Router.onBeforeAction(isX, {
only: ["xPage"]
});
Router.route("/xPage", {
name: "xPage",
action: function() {
this.render("xPage");
}
});
Upvotes: 1