流星:将管理员路由限制为管理员角色
Meteor: Restricting an admin route only to admin roles
我正在尝试将路由限制为仅限角色为管理员的用户
Router.route('/admin', {
if(Roles.userIsInRole(Meteor.user(), ['admin'])) {
template: 'admin' };
else
template: 'restricted'
});
返回了意外的令牌
template
Iron Router 选项适用于您只需要路由到常量模板的简单情况,该模板永远不会更改,也不需要任何特定参数。
如果您的路由更复杂(例如您 return 基于当前用户角色的不同模板),则必须改用 action
路由选项。
请注意,如果您使用 Iron Router,新语法为 Router.route('/path', actionFunction)
由于 ghy s 的建议,设法让它工作。我已将其更新为
Router.route('/admin', {
action: function() {
if(Roles.userIsInRole(Meteor.user(), ['admin'])) {
this.render('admin') }
else
this.render('denied')
}
});
如果有人可以提供更严格和安全的代码,请输入:D 谢谢
我正在尝试将路由限制为仅限角色为管理员的用户
Router.route('/admin', {
if(Roles.userIsInRole(Meteor.user(), ['admin'])) {
template: 'admin' };
else
template: 'restricted'
});
返回了意外的令牌
template
Iron Router 选项适用于您只需要路由到常量模板的简单情况,该模板永远不会更改,也不需要任何特定参数。
如果您的路由更复杂(例如您 return 基于当前用户角色的不同模板),则必须改用 action
路由选项。
请注意,如果您使用 Iron Router,新语法为 Router.route('/path', actionFunction)
由于 ghy s 的建议,设法让它工作。我已将其更新为
Router.route('/admin', {
action: function() {
if(Roles.userIsInRole(Meteor.user(), ['admin'])) {
this.render('admin') }
else
this.render('denied')
}
});
如果有人可以提供更严格和安全的代码,请输入:D 谢谢