我一直在我的 Meteor 项目中使用 Collection2 和 Autoform,让事情变得简单多了!
但是,当我删除 insecure 时,它不再插入(Autoform 提交按钮)。我预料到了!
但是,我已经搜索过,但找不到使它起作用的标准方法?我在 lib 文件夹中定义了一个架构,我的 Autoform 作为模板中的快速表单。我知道我需要允许客户端插入(我不想这样做)或将其传输到服务器端(可能使用方法?)
如有任何建议,我们将不胜感激!我正在寻找实现它的标准方法。
最佳答案
经过大量挖掘后找到了我自己的答案。为插入、更新和删除创建了允许规则:
Posts = new Mongo.Collection('posts');
//SECURITY - Allow Callbacks for posting
Posts.allow({
insert: function(userId, doc) {
// only allow posting if you are logged in
return !! userId;
},
update: function(userId, doc) {
// only allow updating if you are logged in
return !! userId;
},
remove: function(userID, doc) {
//only allow deleting if you are owner
return doc.submittedById === Meteor.userId();
}
});
//Schema then defined as usual
请注意,submittedById 是我的集合中保留 userId 的字段。如果您将其命名为不同的名称,请更改它!
希望这对遇到类似问题的人有所帮助。
关于javascript - 使用 Autoform 插入并删除不安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27281645/