Exception in deferred callback: Error: If the modifier option is true, the validation object must have at least one statement

I am trying to add a role package and then set a custom user role as Guest or Member so that I can use it with paid plans. I am getting the following error:

Exception in defer callback: Error: When the modifier option is true, validation object must have at least one operator
at checkModifier (packages/aldeed:simple-schema/simple-schema-validation.js:271:1)
at doValidation1 (packages/aldeed:simple-schema/simple-schema-validation.js:321:1)

      

When I run the following function

Meteor.methods({
    setUserRole: function(userId, roleToSet){
        // check(Meteor.userId(), String);
        check(userId, String );
        check(roleToSet, String);

        var user = Meteor.users.findOne(userId);

        if (_.isEmpty(user.roles)) {
            Roles.addUsersToRoles(userId, roleToSet);
        }
    }
});

      

+3


source to share


3 answers


This error is triggered by simple-schema , which means that the update method is being used using a modifier that has no operator ($ set, $ unset, .. etc.). The latest version of the roles package seems to avoid this in the code related to Roles.addUsersToRoles, but if the error goes away when you comment out the line where you are using the addUsersToRoles method, then perhaps you need



  • Make sure you are using the latest version of the role pack or using:

    meteor update alanning:roles 
    
          

  • Check the code that calls this method and make sure the arguments are correct and in the correct order

  • Make sure you don't mix the group with the ungrouped model (when using the role package you have to choose whether to always use groups or never use them) .. for example:

     Roles.addUsersToRoles(userId, roles, Roles.GLOBAL_GROUP)
    
          

+1


source


This often means that you are trying a $set

field that has not been added to the schema.



If you are using Telescope, make sure you call Users.addField()

for any fields required by the Roles package.

+1


source


This happens when you apply the schema to user collections.

There are two types of roles :

  roles: {
      type: Object,
      optional: true,
      blackbox: true
  },

      

or

  roles: {
      type: [String],
      optional: true
  }

      

You cannot use both at the same time. In your case, since you are not using groups in Roles.addUsersToRoles(userId, roleToSet);

, you need a second example of defining a role schema.

Just remember that you cannot use groups without changing the schema.

+1


source







All Articles