繁体   English   中英

尝试更新Meteor.users会导致“访问被拒绝”

[英]Attempting to update Meteor.users results in “Access Denied”

我正在处理Meteor项目,并且正在尝试更新特定用户的个人资料。 但是,我总是收到

    update failed: Access denied

我将用户ID存储在变量user_id中,我的代码看起来像

    Meteor.users.update({_id: user_id}, {$set: {'profile.participate_studies': updated_user_list}}) 

但是,如果我这样做

    Meteor.users.update({_id: Meteor.userId()}, {$set: {'profile.participate_studies': updated_user_list}})

更新工作。 这使我认为我存储的ID出现问题。 Meteor.userId()返回的内容和包含id的字符串之间有区别吗? 我知道ID是正确的,因为我可以使用ID在Shell中访问它。

我已经从client查看了更新Meteor.users ,但我没有尝试更新对基本用户对象的编辑。 非常感谢您的帮助!

您可以更新自己的个人资料,所以当您这样做时

Meteor.users.update({_id: Meteor.userId()}, {
  $set: {'profile.participate_studies': updated_user_list}
})

您更新自己的配置文件( Meteor.userId()返回当前登录用户的ID)。

并且当您更新其他用户的个人资料时,您会收到并Access denied错误。

您需要为Meteor.users设置allow规则:

Meteor.users.allow({
  update: function(userId, user) {
    return true; 

    /**
     * Don't use `return true` in production!
     * You probably need something like this:
     * return Meteor.users.findOne(userId).profile.isAdmin;
     */
  }
});

允许规则的完整文档: http : //docs.meteor.com/#/full/allow


提示: 您可以使用简写方式通过ID更新:

Meteor.users.update(Meteor.userId(), {...})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM