允许/拒绝规则中userId和Meteor.userId()之间的区别

时间:2013-09-02 22:24:42

标签: 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: "superheroes" })时,我在控制台中看到2个相等的字符串。 那么,userIdMeteor.userId()之间有什么区别?

1 个答案:

答案 0 :(得分:3)

Meteor.userId()表示当前登录的用户。允许/拒绝规则内的userId表示发起操作的用户。由于你不能把方法调用作为另一个用户,我无法想象这些情况会有所不同。检查允许/拒绝规则中的userId是非常常见的,所以我假设它是为了方便而添加为参数。

相关问题