Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V4.0.0] getRolesForUserAsync() is broken on server #406

Closed
Twisterking opened this issue Sep 11, 2024 · 5 comments
Closed

[V4.0.0] getRolesForUserAsync() is broken on server #406

Twisterking opened this issue Sep 11, 2024 · 5 comments
Labels

Comments

@Twisterking
Copy link

I don't understand what is going on ...

We just upgraded to Meteor 3.0.2 and meteor-roles version 4.0.0.
And somehow, I think, on server the async version of getRolesForUserAsync() is broken.
In a very simple Meteor method, the following gives a totally wrong result:

const rolesOfUser = await Roles.getRolesForUserAsync(await Meteor.userId()); // returns ['admin']
const isAdmin = await Roles.userIsInRoleAsync(await Meteor.userId(), ['admin']); // return false, but should be true

This makes no sense. The same code on client in the sync version works perfectly fine and isAdmin == true.
What am I doing wrong here? This is the very basics of this package ... what is going on here?

I hope someone can help!

best, Patrick

Copy link

Thank you for submitting this issue!

We, the Members of Meteor Community Packages take every issue seriously.
Our goal is to provide long-term lifecycles for packages and keep up
with the newest changes in Meteor and the overall NodeJs/JavaScript ecosystem.

However, we contribute to these packages mostly in our free time.
Therefore, we can't guarantee your issues to be solved within certain time.

If you think this issue is trivial to solve, don't hesitate to submit
a pull request, too! We will accompany you in the process with reviews and hints
on how to get development set up.

Please also consider sponsoring the maintainers of the package.
If you don't know who is currently maintaining this package, just leave a comment
and we'll let you know

@jankapunkt
Copy link
Member

Hi @Twisterking thank you for reporting. Can you please also add to the code example how you created the roles and added the user to the roles so we can use it to reproduce?

@Twisterking
Copy link
Author

Twisterking commented Sep 11, 2024

I debugged this further now by forking the package locally.
Somehow the Collection.countDocuments() method seems broken on Meteor 3.0.2.

If I run this simple code, I actually get a undefined result, which is really weird:

const res = await Meteor.roleAssignment.countDocuments({ 'user._id': 'seDueMBtGiuMCWez6' }); // returns undefined, should return a number
const myRandomRole = await Meteor.roleAssignment.findOneAsync({ 'user._id': 'seDueMBtGiuMCWez6' }); // returns one of my roles

I can make it work very easily if I change the logic of your userIsInRoleAsync() method from countDocuments() to a simple findOneAsync().

Either this is a bug in Meteor 3.0.2 or there is some kind of package in my codebase screwing up this functionality.

@Twisterking
Copy link
Author

I am really sorry everyone ... I found the issue.
Due to a bug in a very old Meteor version, where there was a memory leak in the mongodb driver's collection.count() method back then, we had a monkey patch for countDocuments() in our code ... this broke the logic!

Not a bug, this was our mistake!

@jankapunkt
Copy link
Member

No problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants