0

I am trying to set the role for the logged in user (using alanning:roles package) via a method on the server. Here's what I have...

Client

var userId = Meteor.userId();
Meteor.call('updateRoles',userId,'admin');

And this is the simplified version of the method from the docs...

server/userMethods.js

Meteor.methods({
    updateRoles: function (targetUserId, roles) {
        Roles.setUserRoles(targetUserId, roles)
    }
})

No matter what I try I keep getting the following error...

Error invoking Method 'updateRoles': Internal server error [500]
Serks
  • 333
  • 2
  • 21
  • Note that using that Method any user can set themselves as admin. – Michel Floyd Jan 15 '16 at 05:59
  • Yes, I know, I simplified the method to ask the question as I was certain the issue was not related to the omitted code. I will be using the same method from the docs. – Serks Jan 15 '16 at 06:20

1 Answers1

0

Problem solved.

The reason was because I am using autoform (simple schema) for the 'users' collection and I needed to include the following (uncommented part) in the schema...

// Add `roles` to your schema if you use the meteor-roles package.
// Option 1: Object type
// If you specify that type as Object, you must also specify the
// `Roles.GLOBAL_GROUP` group whenever you add a user to a role.
// Example:
// Roles.addUsersToRoles(userId, ["admin"], Roles.GLOBAL_GROUP);
// You can't mix and match adding with and without a group since
// you will fail validation in some cases.
//
//roles: {
//    type: Object,
//    optional: true,
//    blackbox: true
//},
// Option 2: [String] type
// If you are sure you will never need to use role groups, then
// you can specify [String] as the type

roles: {
    type: [String],
    optional: true
},
Serks
  • 333
  • 2
  • 21