流星alanning:角色 - 错误调用方法'updateRoles':内部服务器错误[500]
问题描述:
我想通过服务器上的方法为登录用户(使用alanning:roles包)设置角色。这是我有...流星alanning:角色 - 错误调用方法'updateRoles':内部服务器错误[500]
客户
var userId = Meteor.userId();
Meteor.call('updateRoles',userId,'admin');
这是method from the docs的简化版本...
服务器/ userMethods.js
Meteor.methods({
updateRoles: function (targetUserId, roles) {
Roles.setUserRoles(targetUserId, roles)
}
})
无论我尝试什么,我都会收到以下错误...
Error invoking Method 'updateRoles': Internal server error [500]
答
问题已解决。
的原因是因为我使用了“用户”收集自动窗体(简单模式),我需要包括在该模式下(未加注释部分)...
// 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
},
注意使用方法任何用户都可以将自己设为管理员。 –
是的,我知道,我简化了问题的方法,因为我确定问题与省略的代码无关。我将从文档中使用相同的方法。 – Serks