userId 和 Meteor.userId() 在允许/拒绝规则中的区别 [英] Difference between userId and Meteor.userId() in allow/deny rules
问题描述
我有一个集合,其中一些允许规则:
I have a collection and some allow rules on it:
Teams = new Meteor.Collection("teams")
Teams.allow({
insert: function(userId, doc) {
console.log(userId);
console.log(Meteor.userId());
// do some stuff
}
})
当我执行 Teams.insert({ name: "superheroes" })
时,我在控制台中看到 2 个相等的字符串.那么,userId
和 Meteor.userId()
有什么区别?
When I do Teams.insert({ name: "superheroes" })
i see 2 equal strings in console.
So, what the difference between userId
and Meteor.userId()
?
推荐答案
Meteor.userId()
表示当前登录的用户. userId
内允许/deny 规则表示发起操作的用户.由于您不能以其他用户的身份进行方法调用,因此我无法想象这些情况会有所不同.在允许/拒绝规则中检查 userId
真的很常见,所以我认为它被添加为一个参数只是为了方便.
Meteor.userId()
means the user which is currently logged in. userId
inside of an allow/deny rule means the user that initiated the action. Since you can't make a method call as another user, I can't imagine a situation where these would ever be different. Checking the userId
in an allow/deny rule is really common, so I assume it was added as an argument just for convenience.
这篇关于userId 和 Meteor.userId() 在允许/拒绝规则中的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!