Meteor alanning:roles - 调用方法 'updateRoles' 时出错:内部服务器错误 [500]
Meteor alanning:roles - Error invoking Method 'updateRoles': Internal server error [500]
我正在尝试通过服务器上的方法为登录用户设置角色(使用 alanning:roles 包)。这就是我所拥有的...
客户端
var userId = Meteor.userId();
Meteor.call('updateRoles',userId,'admin');
这是 method from the docs...
的简化版本
server/userMethods.js
Meteor.methods({
updateRoles: function (targetUserId, roles) {
Roles.setUserRoles(targetUserId, roles)
}
})
无论我尝试什么,我都会收到以下错误...
Error invoking Method 'updateRoles': Internal server error [500]
问题已解决。
原因是因为我正在为 'users' 集合使用自动表单(简单模式),我需要在模式中包含以下(未注释的部分)...
// 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
},
我正在尝试通过服务器上的方法为登录用户设置角色(使用 alanning:roles 包)。这就是我所拥有的...
客户端
var userId = Meteor.userId();
Meteor.call('updateRoles',userId,'admin');
这是 method from the docs...
的简化版本server/userMethods.js
Meteor.methods({
updateRoles: function (targetUserId, roles) {
Roles.setUserRoles(targetUserId, roles)
}
})
无论我尝试什么,我都会收到以下错误...
Error invoking Method 'updateRoles': Internal server error [500]
问题已解决。
原因是因为我正在为 'users' 集合使用自动表单(简单模式),我需要在模式中包含以下(未注释的部分)...
// 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
},