Meteor alanning:角色-调用方法时出错';updateRoles';:内部服务器错误[500]
我试图通过服务器上的方法为登录用户(使用包)设置角色。这是我所拥有的 客户端Meteor alanning:角色-调用方法时出错';updateRoles';:内部服务器错误[500],meteor,user-roles,Meteor,User Roles,我试图通过服务器上的方法为登录用户(使用包)设置角色。这是我所拥有的 客户端 var userId = Meteor.userId(); Meteor.call('updateRoles',userId,'admin'); 这是简化版的 server/userMethods.js Meteor.methods({ updateRoles: function (targetUserId, roles) { Roles.setUserRoles(targetUserId,
var userId = Meteor.userId();
Meteor.call('updateRoles',userId,'admin');
这是简化版的
server/userMethods.js
Meteor.methods({
updateRoles: function (targetUserId, roles) {
Roles.setUserRoles(targetUserId, roles)
}
})
无论我尝试什么,我总是会出现以下错误
Error invoking Method 'updateRoles': Internal server error [500]
问题解决了
原因是我正在为“用户”集合使用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
},
请注意,使用该方法,任何用户都可以将自己设置为管理员。是的,我知道,我简化了询问问题的方法,因为我确信问题与省略的代码无关。我将使用文档中的相同方法。