gpt4 book ai didi

javascript - 在 Meteor 中更新用户帐户客户端时访问被拒绝 [403]

转载 作者:行者123 更新时间:2023-11-29 10:12:01 32 4
gpt4 key购买 nike

我正在阅读 Meteor 的文档 here和 useraccounts 包 here但找不到答案。我已成功添加 useraccounts 包并创建了一些用户,但现在我想将一些数据添加到给定用户的集合中的记录中。

例如,在帐户创建和登录之后。我希望用户能够在他们的记录中添加/编辑一些字段(简短的传记等),但是每当执行 Meteor.users.update(..) 时我总是收到 403 错误>.

可以找到我的登录配置文件here .

导致错误的代码:

Template.editProfile.events({
'submit form': function(e) {
e.preventDefault();

var profileInfo = {
displayName: $(e.target).find('[name=displayName]').val(),
tagLine: $(e.target).find('[name=tagLine]').val(),
aboutMe: $(e.target).find('[name=aboutMe]').val()
};

Meteor.users.update(
{ _id: Meteor.userId()},
{ $set: profileInfo},
function (err) {
if(err) {
console.log('there was an error submitting editProfile data');
console.log(err);
} else {
Router.go('profile');
}
}
);
}
});

控制台日志显示 Meteor.userId() 正确返回,所以我不确定问题出在哪里。我假设这是允许/拒绝的问题,但我什至不知道从哪里开始进行故障排除。

准确的错误是:

error: 403

errorType: "Meteor.Error"

message: "Access denied [403]"

reason: "Access denied"

最佳答案

通过删除insecure 包,默认情况下将拒绝客户端写访问。如果要允许客户端直接写入集合,则需要定义规则。

例如:

Meteor.users.allow({
update: ownsDocument
});

ownsDocument = function (userId, doc) {
return doc && doc.userId === userId;
};

ownsDocument() 函数检查指定的 userId 是否拥有文档。除了 update 回调之外,您还可以为 insertremove 设置规则。

阅读更多关于 Meteor's collection.allow(options) 的信息, 访问 demo appclone the repository .

关于javascript - 在 Meteor 中更新用户帐户客户端时访问被拒绝 [403],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31631810/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com