I can't use alanning:roles package


#1

Hi,

I’ve used alanning roles package in my previous app with succes, but I can’t figure out what is wrong with my new app.

I am using this client side:

Roles.userIsInRole(Meteor.userId(), ['super-admin']);
Which returns false when I am logged-in.

I can see my role in the database:

meteor:PRIMARY> db.users.find().pretty();
{
        "_id" : "KMMyiMNrAsn24H8HP",
        "createdAt" : ISODate("2017-10-11T15:13:28.010Z"),
        "services" : {
                "password" : {
                        "bcrypt" : "$2a$10$h9OwJ/bUzlDZtMTgERfvqeu0AoRujzr7/.yxwYjbWJrPJZLZfILtO"
                },
                "resume" : {
                        "loginTokens" : [
                                {
                                        "when" : ISODate("2017-10-11T16:15:52.162Z"),
                                        "hashedToken" : "gC9/FKIu2EYxm03pfya/Enr3AaQRf+51zG6wuTT14xo="
                                },
                                {
                                        "when" : ISODate("2017-10-11T16:23:54.345Z"),
                                        "hashedToken" : "QcZn5Xf1Kk9ilPnd2RQ2bWPRtX/IcmY4KDq/GBgb7TU="
                                }
                        ]
                }
        },
        "emails" : [
                {
                        "address" : "my@email.com",
                        "verified" : false
                }
        ],
        "roles" : {
                "__global_roles__" : [
                        "super-admin"
                ]
        }
}

I tried with raw values console.log(Roles.userIsInRole('KMMyiMNrAsn24H8HP', ['super-admin']));
But is still returns false… what’s wrong here?

Thanks.


#2

I think you need to specify the group for the role (which in your case is the special global group)

Roles.userIsInRole('KMMyiMNrAsn24H8HP', ['super-admin'], Roles.GLOBAL_GROUP)

#3

Actualy it was just because I was calling the function before my users publications were ready. And it wasn’t in a reactive function so it didn’t run again once ready.

Thanks for the help.