【问题标题】:Meteor DDP contextMeteor DDP 上下文
【发布时间】:2015-06-16 06:30:33
【问题描述】:

我正在为分布式 ddp 客户端创建包

基本套路如下:

  1. 客户端连接
  2. 如果它是新的,它会使用 Diffie-Hellman 密钥交换算法协商自己的密钥和秘密
  3. 然后使用密钥和加密密码登录

用户可以通过使用给定的 ip 搜索将客户分配给他们的帐户

这样我们就有了自动客户端注册。

我要解决的是在服务器端设计类似于 Meteor.userId 的功能

步骤1: ddp客户端登录,(跳过DH算法)

//client:
DDPClient.call('register',[key:key,token:token, ip:ip]);

//server
Meteor.methods({
  'register' : function(options){
    var self = this;
    // check key token

    // store registered clientId similar to Meteor.userId in currentContext
    // self contains field _sessionData;
    // storing data inside this method works fine 
    _.extend(self._sessionData, {clientId: ID }
  }
});

第二步: ddp客户端调用其他方法

//client:
DDPClient.call('other-method',[]);

//server
Meteor.methods({
  'other-method' : function(options){
    var self = this;
    //this returns what we set inside register method
    console.log(self._sessionData.clientId);
  }
});

问题在于 Meteor.publish 方法是否有一些简单的方法可以在当前上下文中使用有效的 ClientID 重新启动所有订阅?我可以遵循 livedata 包中的 setUserId 方法,但它使用了很多我不想接触的内部结构

这必须工作

Meteor.publish('data' : function(){
  var self = this;

  var clientId = ?????

  return Data.find({owner : clientId});
});

或者还有其他方法可以完成我的任务吗? 我只是想在上下文中保留客户端 ID,这样它就不必对每个方法调用进行授权

这个解决方案是不可接受的

Meteor.publish('data', function(clientId){

});

【问题讨论】:

    标签: meteor ddp


    【解决方案1】:

    Meteor.userId() 已经存在于服务器端,位于发布功能以外的任何位置。如果您在发布函数中,则可以改用this.userId

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-17
      相关资源
      最近更新 更多