允许/拒绝规则中userId和Meteor.userId()之间的差异
我有一个集合和一些允许规则:允许/拒绝规则中userId和Meteor.userId()之间的差异,meteor,Meteor,我有一个集合和一些允许规则: Teams = new Meteor.Collection("teams") Teams.allow({ insert: function(userId, doc) { console.log(userId); console.log(Meteor.userId()); // do some stuff } }) 当我执行Teams.insert({name:“superheros”})时,我在控制台
Teams = new Meteor.Collection("teams")
Teams.allow({
insert: function(userId, doc) {
console.log(userId);
console.log(Meteor.userId());
// do some stuff
}
})
当我执行Teams.insert({name:“superheros”})
时,我在控制台中看到两个相等的字符串。
那么,userId
和Meteor.userId()
之间的区别是什么?Meteor.userId()
表示当前登录的用户<代码>用户ID在允许/拒绝规则中表示发起操作的用户。因为您不能作为另一个用户进行方法调用,所以我无法想象在什么情况下它们会有所不同。在允许/拒绝规则中检查userId
非常常见,因此我假设它是作为一个参数添加的,只是为了方便。Meteor.userId()
表示当前登录的用户<代码>用户ID在允许/拒绝规则中表示发起操作的用户。因为您不能作为另一个用户进行方法调用,所以我无法想象在什么情况下它们会有所不同。在允许/拒绝规则中检查userId
确实很常见,因此我假设它是为了方便而作为参数添加的