我正在尝试通过服务器上的方法为登录用户设置角色(使用alanning:roles包)。这就是我的......
客户端
static get bar() { return 42; }
这是method from the docs ...
的简化版本服务器/ userMethods.js
var userId = Meteor.userId();
Meteor.call('updateRoles',userId,'admin');
无论我尝试什么,我都会收到以下错误......
Meteor.methods({
updateRoles: function (targetUserId, roles) {
Roles.setUserRoles(targetUserId, roles)
}
})
答案 0 :(得分:0)
问题解决了。
原因是因为我正在为“用户”使用autoform(简单模式)。集合,我需要在模式中包含以下(未注释的部分)...
// 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
},