【发布时间】:2017-10-22 10:02:22
【问题描述】:
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}
});
})
【问题讨论】: