我正在用React构建一个Meteor应用程序。我的问题是,alanning:roles包似乎不像预期的那样工作。
没有控制台错误,但以下代码基本上不能按预期工作。
const composer = (props, onData) => {
const loggingIn = Meteor.loggingIn()
const loggedInUserId = Meteor.userId()
console.log(loggedInUserId)
let authenticated
if (Roles.userIsInRole(loggedInUserId, ['admin']))
authenticated = 'admin';
else if (Roles.userIsInRole(loggedInUserId, ['school']))
authenticated = 'school'
else if (Roles.userIsInRole(loggedInUserId, ['teacher']))
authenticated = 'teacher'
else
authenticated = 'anonymous'
console.log(authenticated)
onData(null, {
loggingIn,
authenticated
})
}loggedInUserId变量成功地显示了在第一个console.log()中登录的用户的id。但是,无论登录的是哪个用户,authenticated的值始终是anonymous。
我可以确认,loggedInUserId确实匹配处于相对角色中的用户,但是结果始终是相同的。
这里怎么了?
发布于 2017-04-19 10:57:53
我通过将我的composer改为:
const composer = (props, onData) => {
const loggingIn = Meteor.loggingIn()
const loggedInUserId = Meteor.userId()
let authenticated
if (Roles.userIsInRole(loggedInUserId, 'admin', 'default-group'))
authenticated = 'admin';
else if (Roles.userIsInRole(loggedInUserId, 'school', 'default-group'))
authenticated = 'school'
else if (Roles.userIsInRole(loggedInUserId, 'teacher', 'default-group'))
authenticated = 'teacher'
else
authenticated = 'anonymous'
onData(null, {
loggingIn,
authenticated
})
}当在分配角色时不指定group时,它会自动将角色分配给default-group。
https://stackoverflow.com/questions/43479156
复制相似问题