【问题标题】:Meteor alanning:roles - Error invoking Method 'updateRoles': Internal server error [500]Meteor alanning:roles - 调用方法“updateRoles”时出错:内部服务器错误 [500]
【发布时间】:2016-01-15 14:25:19
【问题描述】:

我正在尝试通过服务器上的方法为登录用户(使用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]

【问题讨论】:

  • 请注意,使用该方法任何用户都可以将自己设置为管理员。
  • 是的,我知道,我简化了提问的方法,因为我确信问题与省略的代码无关。我将使用文档中的相同方法。

标签: meteor user-roles


【解决方案1】:

问题解决了。

原因是因为我在“用户”集合中使用了 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
},

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多