Meteor.userId() 在发布函数中

Meteor.userId() in publish functions

Meteor documentation 明确指出在发布函数中不允许使用 Meteor.userId() 并且应该使用 this.userId 代替它。

我依稀记得过去不小心这样做时看到了警告或错误。

我经常使用共享代码,这些代码既用于验证订阅中的权限,也用于在助手中确定我是否应该实际向特定用户类型显示特定元素。

这使得这种方法非常烦人。我今天在以下出版物中无意中使用了 Meteor.userId(),没有任何问题。

是否取消了此限制?如果是这样,是否有任何随附的文档,因为文档尚未更新。

我正在使用 Meteor 1.5.2.2。

示例出版物是这个...

Meteor.publish("users.currentUser", function(){
  const currentId = Meteor.userId();
  return Meteor.users.find({_id: currentId}, {
    fields: { services: 1, username: 1, emails: 1, roles: 1, details: 1}
  });
})

从 1.5.1 开始 you can use Meteor.userId() and Meteor.user() in publications。好像文档还没有更新。