是否可以将您当前的用户ID传递给远程DDP服务器的`this.userId`?

时间:2014-06-07 01:04:29

标签: meteor ddp

我有两个使用相同数据库的流星应用程序,一个是移动应用程序(主要),另一个是桌面应用程序。

在桌面应用中,我想调用远程移动方法来创建商家信息,这样我就不必复制代码'Listing.create'

我假设我在桌面应用程序上登录Meteor.userId时会调用远程移动方法,但事实并非如此,因为它未定义。

我也有Oauth和电子邮件验证,并且似乎不是一种使用OAuth登录的简单方法(通过电话登录'登录'适用于密码)。

调用远程方法的最佳方法是什么,因为它在没有登录的情况下失败了?我想我可以将userId作为字符串传递但是这会打开方法直到黑客攻击

Mobile server, m.foo.com, MONGO_URL bar.com

Meteor.methods({

  'Listing.create': function(){

    if (!this.userId) throw new Meteor.Error(503, 'No user account');

    ...

    db.listings.insert(...);
  }

})

// on client
Meteor.userId() // 1234


Desktop server, foo.com, MONGO_URL bar.com

MobileDDP = DDP.connect('http://m.foo.com')

MobileDDP.call('Listing.create', function(err, res) {
  console.log(err, res)
});

1 个答案:

答案 0 :(得分:0)

是。该方法与答案相同:Authenticating with Meteor via DDP (and SRP?)

唯一的区别是使用ddp-tools而不是使用Meteor.call("login"..,而是将参数与登录类型相匹配。

如果登录是Facebook或其他OAuth登录,则必须使用loginToken而不是普通的用户名和密码。