Meteor-Community-Packages / meteor-roles

Authorization package for Meteor, compatible with built-in accounts packages
http://meteor-community-packages.github.io/meteor-roles/
MIT License
920 stars 167 forks source link

Roles.userIsInRole(Meteor.userId(),['manager']) is not working in Chrome console with 3.2 #317

Closed FrancoisYu closed 4 years ago

FrancoisYu commented 4 years ago

I've just created a new react app. With alanning:roles@3.2, Roles.userIsInRole(Meteor.userId(),['manager']) always retun false in Chrome console, but if I downgrade to alanning:roles@2.0.1, reset the db, Roles.userIsInRole(Meteor.userId(),['manager']) return true in Chrome console,. Has anyone have the same issue?

SimonSimCity commented 4 years ago

@FrancoisYu I guess you have the same issue as described here: https://github.com/Meteor-Community-Packages/meteor-roles/issues/296

fpreti commented 4 years ago

it seems the same to me too, version 2.1 works correctly while 3.2.2 does not recognize roles

@ after users creation: `var postSignUp = function(userId, info) { console.log(userId); console.log(info.profile.profession); Roles.addUsersToRoles(userId, ['admin']); }

AccountsTemplates.configure({ postSignUpHook: postSignUp });`

and then

``

{{#if isInRole 'admin'}} not working properly

SimonSimCity commented 4 years ago

@fpreti please also check the issue I linked.

If the problem persists, please create a sandbox git-repository here on github and send me a link so I can dig into it.

fpreti commented 4 years ago

i think that the issue that you linked it's not reflect our case, i will create a sandbox repo

fpreti commented 4 years ago

@SimonSimCity https://github.com/fpreti/meteor-roles-issue-317

FrancoisYu commented 4 years ago

I've also created a very simple repo. without any UI for testing only: https://github.com/FrancoisYu/roles-test.git

Take the following steps to re-generate the error:

  1. git clone

  2. cd roles-test && meteor npm install

  3. meteor

Open Chrome to access http://localhost:3000

Open the developer console, input the following command:

Meteor.loginWithPassword('test@gmail.com','test') undefined

Roles.userIsInRole(['admin']) false

Meteor.call('checkIfAdmin', (err,res)=>{console.log(res )}); true

And if you check the server console , it return true too.

SimonSimCity commented 4 years ago

@FrancoisYu Well, there's one thing you did wrong when calling it on the client side: You didn't give a user-id or an user object to the function Roles.userIsInRole(), but on the server side you did.

It returns true calling it like this: Roles.userIsInRole(Meteor.userId(), ['admin'])

That said, your code returns the expected result when using the command of the description you initially wrote when opening this issue.

SimonSimCity commented 4 years ago

@fpreti If you are just updating without changing anything in code, you did not read the update notices (https://github.com/Meteor-Community-Packages/meteor-roles#changes-between-2x-and-30). Please follow those steps first and open a new ticket if you still face problems.

FrancoisYu commented 4 years ago

Thanks. SimonSimCity, Now I got the "true".