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

_roles publication doesn't publish Meteor.roles in v3 #346

Open
jrkinclus opened this issue Sep 30, 2021 · 0 comments
Open

_roles publication doesn't publish Meteor.roles in v3 #346

jrkinclus opened this issue Sep 30, 2021 · 0 comments
Labels

Comments

@jrkinclus
Copy link

jrkinclus commented Sep 30, 2021

Calling, say, Roles.addUsersToRoles on client-side in a Meteor method doesn't work due to roles not being published. Causing this kind of error (trying to add user to a role called 'admin'):

Error: Role 'admin' does not exist.
    at Object._addUserToRole (roles_common.js:473)
    at roles_common.js:380

If it's intended that this should work client-side too and you don't have to wrap all such calls inside a if (Meteor.isServer) { block, then this is an issue. Server-side it works of course.

The problem seems to be that the automatically subscribed _roles publication doesn't seem to do doing what it should. In v3.4.0 it's still publishing what looks like v1 format roles for the current user:
https://github.com/Meteor-Community-Packages/meteor-roles/blob/v3/roles/roles_server.js#L16

Meteor.publish('_roles', function () {
  var loggedInUserId = this.userId
  var fields = { roles: 1 }

  if (!loggedInUserId) {
    this.ready()
    return
  }

  return Meteor.users.find(
    { _id: loggedInUserId },
    { fields: fields }
  )
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants