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

cannot add data into role-assignment #362

Closed 113475 closed 1 year ago

113475 commented 1 year ago

may I know what is the proper way to fetch role-assignment data from the database and add data to role-assignment. My code only create the role-assignment collection in database but never add data into it. Also may I know what is the proper way to fetch the user-role data from db? Does I need to set up any publish for the role-assignment?

Here is my code:

import { Meteor } from 'meteor/meteor';
import { BinRoles } from './BinRoles';

Roles.createRole(BinRoles.ADMIN, { unlessExists: true });

Meteor.startup(() => {
  const user = Meteor.users.findOne({ email: '12313@gmail.com' });
  if (!user || Roles.userIsInRole(user._id, BinRoles.ADMIN)) {
    return;
  }

  Roles.addUsersToRoles(user._id, BinRoles.ADMIN);
});

and also for the createRole function, as I check in roles_common.js it can accept two parameters, however when I use it only accept one param.

github-actions[bot] commented 1 year ago

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

StorytellerCZ commented 1 year ago

Make sure to import the Roles object:

import { Roles } from 'meteor/alanning:roles'

Also where are you running that code? On the client or server? On the first look your code looks fine.

113475 commented 1 year ago

Thanks, the problem has been solved