【发布时间】:2017-11-05 14:35:03
【问题描述】:
我正在使用FlowRouter 和FlowTemplate 和both/router/router.js 我正在检查它是角色admin 的用户:
....
action: function () {
if(Roles.userIsInRole(Meteor.userId(), 'admin')){
FlowLayout.render('layout', {
sidebar: 'sidebar', main:'admin', cart:'cart'
})
} else {
FlowLayout.render('layout', {
sidebar: 'sidebar', main:'unauthorised', cart:'cart'
})
}
console.log(Meteor.userId());
}
....
并返回FALSE,但是当我在WEB控制台中使用它时是TRUE。这行console.log(Meteor.userId()); 输出正确的userID,当我登录时,如果我在WEB 控制台Roles.userIsInRole(Meteor.userId(), 'admin') 中执行此操作,则为TRUE。如果我这样做Meteor.user().roles,结果是['admin']
如果我签入模板是角色中的用户:
{{#if isInRole 'admin' }}
ADMIN
{{/if}}
它是TRUE,但在router.js 中返回FALSE。
如何解决?
【问题讨论】:
标签: javascript meteor meteor-accounts