【问题标题】:Meteor.call access to authenticated User data?Meteor.call 访问经过身份验证的用户数据?
【发布时间】:2013-10-14 21:45:07
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: security authentication meteor user-input


    【解决方案1】:

    这很容易。

    Meteor.user()Meteor.userId() 在服务器上可用的方式与在客户端上的方式相同——由 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 {};
        }
      }
    };
    

    【讨论】:

      猜你喜欢
      • 2016-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-01
      • 2014-03-26
      • 1970-01-01
      • 2020-11-15
      • 2016-01-17
      相关资源
      最近更新 更多