我在向Meteor用户对象(Meteor.user)添加自定义用户字段时遇到问题.我希望用户有一个"状态"字段,我宁愿不将它嵌套在"profile"(即profile.status)下,我知道默认情况下是r/w.(我已经删除了autopublish.)
我已经能够将该字段发布到客户端了
Meteor.publish("directory", function () {
return Meteor.users.find({}, {fields: {username: 1, status: 1}});
});
Run Code Online (Sandbox Code Playgroud)
...但我无法获得允许登录用户更新自己的权限status.
如果我做
Meteor.users.allow({
update: function (userId) {
return true;
}});
Run Code Online (Sandbox Code Playgroud)
在Models.js,用户中可以编辑每个用户的所有字段.这不酷.
我试过做变种,比如
Meteor.users.allow({
update: function (userId) {
return userId === Meteor.userId();
}});
Run Code Online (Sandbox Code Playgroud)
和
Meteor.users.allow({
update: function (userId) {
return userId === this.userId();
}});
Run Code Online (Sandbox Code Playgroud)
他们只是在控制台中找到了Access Denied错误.
该文件解决了几分这一点,但不会进入足够的细节.我犯的是什么愚蠢的错误?
(这与此 SO问题类似,但该问题仅涉及如何发布字段,而不是如何更新字段.)