2016-01-15 53 views
0

我想通過服務器上的方法爲登錄用戶(使用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] 
+0

注意使用方法任何用戶都可以將自己設爲管理員。 –

+0

是的,我知道,我簡化了問題的方法,因爲我確定問題與省略的代碼無關。我將從文檔中使用相同的方法。 – Serks

回答

0

問題已解決。

的原因是因爲我使用了「用戶」收集自動窗體(簡單模式),我需要包括在該模式下(未加註釋部分)...

// 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 
}, 
相關問題