Meteor.call访问经过身份验证的用户数据?

时间:2013-10-14 21:45:08

标签: security authentication meteor user-input

在Meteor中,在客户端上,很容易确定用户。

客户端可以通过Meteor.call(params)向服务器发送请求/参数。

如何从服务器获取登录的用户数据?

(从客户端传递到服务器是不安全的)

1 个答案:

答案 0 :(得分:0)

那很容易。

Meteor.user()Meteor.userId()在服务器上的可用方式与客户端相同 - 由Meteor核心安全管理和验证。

Kudos Meteor团队!

Meteor.methods({
  myFancyFunc1: function(args) {
    var user = Meteor.user();
  },
  myFancyFunc2: function(args) {
    var user = AbstractClass.getUser();
  }
});
AbstractClass = {
  getUser: function() {
    if (Meteor.isServer) {
      // are we initiated via DDP (with access to Auth, Meteor.call)
      var currentInvocation = DDP._CurrentInvocation.get();
      if (currentInvocation) {
        // return logged in user as passsed through
        return Meteor.user();
      }
      // we don't know the user details, return empty object instead
      return {};
    }
  }
};