首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Roles.userIsInRole不工作

Roles.userIsInRole不工作
EN

Stack Overflow用户
提问于 2017-04-18 17:57:24
回答 1查看 477关注 0票数 0

我正在用React构建一个Meteor应用程序。我的问题是,alanning:roles包似乎不像预期的那样工作。

没有控制台错误,但以下代码基本上不能按预期工作。

代码语言:javascript
复制
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确实匹配处于相对角色中的用户,但是结果始终是相同的。

这里怎么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-19 10:57:53

我通过将我的composer改为:

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43479156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档