【问题标题】:Meteor useraccounts:core role emptyMeteor 用户帐户:核心角色为空
【发布时间】:2020-05-25 12:09:31
【问题描述】:

我正在尝试通过视频教程学习 Meteor 来完成代码并没有得到相同的结果。代码如下:

Meteor.startup(function(){
if(Meteor.users.find().count() < 1){
    var users= [
        {
            name: "Superuser",
            email: "admin@example.com",
            roles: ['admin']
                        }
                ];

    _.each(users, function(user){
        var id;

        id = Accounts.createUser({
            email: user.email,
            password: "password",
            profile:{
                name: user.name
            }
        });

        if(user.roles.length > 0){
            Roles.addUsersToRoles(id, user.roles);
        }
    });
}

});

假设 Meteor.roles.find.().fetch() 控制台应该出现:对象名称:'admin'_id。 '任何';但我的弹出我空[]。

我正在使用alanning:来自大气js 的角色

提前致谢。

【问题讨论】:

  • 你确定你在服务器端运行这个吗?看到 Mongo 数据库中的新用户了吗?
  • 是的,它在服务器端,mongo 上的 db.roles.find () 显示为空。 ://

标签: javascript authentication meteor atmosphere meteor-accounts


【解决方案1】:

您是否安装了 accounts-ui 和 accounts-passwords 软件包?可能与此有关。我建议你安装 meteortoys:allthings 来检查你的数据库有什么问题。

【讨论】:

    【解决方案2】:
    Meteor.startup(function() {
        if (Meteor.users.find().count() < 1) {
          var users = {
            name: "Superuser",
            email: "admin@example.com",
            roles: ['admin']
          };
          var id;
          id = Accounts.createUser({
            email: user.email,
            password: "password",
            profile: {
              name: user.name
            }
          });
          if (user.roles.length > 0) {
            Roles.addUsersToRoles(id, user.roles, 'defaultgroup');
          }
        });
    }
    

    【讨论】:

    • 这个工具看起来不错,@ParthRaval Toys Meteor 显示:meteor.loginServiceConfiguration Params:none _roles Params:none meteor_autoupdate_clientVersion Params:none
    • 您必须在用户模型角色中添加:{ type: Object }
    • 这行得通,最后请注意,没有进行更改,因为之前已经创建了用户,只是删除了数据库,一切正常。非常感谢。 @ParthRaval
    猜你喜欢
    • 2016-04-17
    • 2019-09-26
    • 1970-01-01
    • 2020-07-08
    • 2018-05-14
    • 2013-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多