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);
}
}
});
source to share
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)
source to share
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.
source to share