【问题标题】:Meteor.userId() in publish functions发布函数中的 Meteor.userId()
【发布时间】: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}
  });
})

【问题讨论】:

    标签: meteor meteor-accounts


    【解决方案1】:

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

    【讨论】:

    • 这是一个巨大的变化,解决了使用同构代码库的重大障碍。
    猜你喜欢
    • 2013-05-19
    • 2014-08-10
    • 1970-01-01
    • 2016-09-02
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多