Skip to content

Roles.getRolesForUser() returns [] (empty array) #415

@Berchez

Description

@Berchez

Describe the bug

TL;DR - My Roles.getRolesForUser() always returns an empty array (even on the server-side).

Hi, I read the documentation and published it:

Meteor.publish(null, function() { if (this.userId) { return Meteor.roleAssignment.find({ 'user._id': this.userId }); } else { this.ready(); } });

However, even with the publication, my Roles.getRolesForUser() calls don't return anything. Regardless of whether it's on the client or the server.

I also read the issue #296 where the guy forgot to import the publication (which is not my case).

Other methods from v3 work normally in my code. (I haven't been able to test them all yet).

Meteor.roleAssignment.find({ 'user._id': this.userId }).fetch(), normally returns my user's roles.

To Reproduce

After migrating from v1 to v2 and finally v3, I just call Roles.getRolesForUser(userId) inside a useEffect or inside a meteor method and it returns []

Expected behavior

Return a result similar to Meteor.roleAssignment.find({ 'user._id': this.userId }).fetch() when I call Roles.getRolesForUser(this.userId)

Versions (please complete the following information):

  • Meteor version: Meteor 2.16
  • Browser: Chrome v132.0.6834.111
  • Version: alanning:roles@3.6.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions