【问题标题】:Accounts With roles MeteorJS具有角色的帐户 MeteorJS
【发布时间】:2015-06-23 09:02:05
【问题描述】:

我使用alanning-roles 包和 Meteor.method 来创建具有角色的帐户,但创建的帐户没有任何角色。

浏览器控制台抛出Internal 505 error,服务器控制台抛出invalid createUser Method.

这是我的方法。

Meteor.methods({
 createUser:function(password,email,username){ //Normal Account
  var rol = "Normal",
       account = Accounts.createUser({
               email:email,
               password:password,
               username:username
          });
        console.log(account) //returns id wich i need to add the user to the rol
        Roles.addUsersToRoles(account, rol);
      return account;
   }
})

并像在事件处理程序上一样调用它。

Meteor.call('createUser',"example123","example@gmail.com","example",function(error,account){
 if(error){
   console.log(error.reason)
  }else{
   console.log("user created")
   }
})

【问题讨论】:

    标签: javascript meteor roles


    【解决方案1】:
    Internal 505 error //this means something get wrong on the server, so the Meteor.call is ok.
    

    服务器方法也可以,但是你需要将 rol 包装在一个数组中,像这样。

    var rol = ["Normal"]
    

    角色字段类似于Accounts-Package 上的电子邮件字段。

    【讨论】:

    • 感谢您的回答,让我试试更新:感谢 ethan 它可以工作,为什么它应该是一个数组而不是一个字符串?
    猜你喜欢
    • 2019-09-08
    • 2021-07-25
    • 2014-07-16
    • 2017-09-10
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    相关资源
    最近更新 更多