登录后Meteor.user()未完全加载

Syl*_*inB 3 field accounts meteor

我正在使用Meteor 0.8.2和accounts-facebook.我以这种方式为用户设置了一个有限的出版物:

Meteor.publish('users', function () {
  return Meteor.users.find({}, {fields: {'profile.picture': 1, 'profile.gender':1, 'profile.type':1}, sort: {'profile.likes': -1}});
});
Run Code Online (Sandbox Code Playgroud)

现在这很好用:当我从客户端请求用户列表时,我得到所有用户的列表,其中显示当前用户的所有字段,并且仅显示其他用户的3个已发布字段.除外:登录后立即

当我登录并输入时Meteor.user(),这是我得到的:

_id: "uACx6sTiHSc4j4khk"
profile: Object { gender="male", type="1", picture="http://....jpg"}
Run Code Online (Sandbox Code Playgroud)

这一直保持不变,直到我使用浏览器按钮刷新页面.刷新后,Meteor.user()提供所有可用字段,同时Meteor.users.find()仍然给出正确的限制.(当然除了当前用户)

为什么我当前的用户不能立即获得所有字段?我读到了一个Meteor.userLoaded()用于等待用户加载的方法,但它似乎在最新版本中已经过时了.

And*_*Mao 5

您正在遇到跨发布的合并字段限制与发送profile字段的默认用户发布之间的交互.

首先,请注意,有一个内置的出版物始终将当前登录用户的整个profile字段发送给该用户:

https://github.com/meteor/meteor/blob/devel/packages/accounts-base/accounts_server.js#L1172

其次,目前不支持在多个级别深度合并字段:

https://github.com/meteor/meteor/issues/998

您目前拥有的是默认发布发送类似以下内容的问题

{
  username: ...,
  emails: [ ... ],
  profile: { 
    ... all fields ... 
  }
}
Run Code Online (Sandbox Code Playgroud)

而您设置的出版物正在发送

{
  profile: {
    picture: ...
    gender: ...
    type: ...
  }
}
Run Code Online (Sandbox Code Playgroud)

这些将根据订阅解析规则(http://docs.meteor.com/#meteor_subscribe)合并到客户端.特别是,请参阅最后一段.流星知道合并username,并email与场profile域.但是,它并没有在内部层面进行合并.因此,其中一个profile字段将被任意选择显示在客户端的集合中.如果第一个获胜,你会看到profile.likes.如果第二个赢了,你就不会.

这种行为可能在某种程度上是确定性的,并且会根据是否调用普通登录处理程序或恢复处理程序(即重新加载浏览器时)而发生变化.因此,为什么它看起来没有加载.