1

accounts-password使用andaccounts-ui模块创建用户后,当我Meteor.user()在控制台中调用时,我没有得到完整的配置文件,只有_idand username,即使文档上有更多内容,比如createdAt记录。

如果我使用这些模板,也会出现同样的问题:

<template name="user_list">
    <div class="user-list">
    <h1>Users</h1>
        <ul>
        {{#each allUsers}}
            {{> user_item}}
        {{/each}}
        </ul>
    </div>
</template>

<template name="user_item">
    <li class="user-item">
        <p><b>{{username}}</b></p>
        <p>Created: {{createdAt}}</p>
    </li>
</template>

...由这个助手支持:

Template.user_list.helpers({
  allUsers: function () {
    return Meteor.users.find({});
  }
});

在这种情况下,user_list 模板很好地遍历了用户,并显示了用户名,但createdAt帮助程序失败了,即使我通过meteor mongo记录肯定存在。我没有删除自动发布;我的设置仍然完全开放。为什么我不能访问其余的用户记录?

4

1 回答 1

6

默认情况下,accounts 包只发布 id、username 和 profile 字段。要发布更多内容,请将此“通用”发布添加到服务器:

Meteor.publish(null, function() {

  if (this.userId != null) {
    return Meteor.users.find({
      _id: this.userId
    }, {
      fields: {
        'createdAt': 1,
      }
    });
  } else {
    return this.ready();
  }
});

注意:this.ready()即使没有用户,它也会返回以确保与 Spiderable 包的兼容性。

于 2015-02-14T10:25:56.130 回答