How can I utilize `this.userId` from a Meteor Method call?

时间:2015-10-31 00:16:29

标签: meteor

Currently I have two apps, 'Alpha' and 'Bravo', split-up to reduce code size. However now I need 'Bravo' app to call a Meteor method written in the 'Alpha' app (from the client) and it needs to utilize the this.userId for security. However, currently this.userId is null if called from 'Bravo' app. The 'Bravo' app creates users by duplicating createUser code and sharing the same database. The user can log into each app with no issues. It also connects to Alpha using: AlphaDDP = DDP.connect(alpha_server_url) However when in Bravo app if I call AlphaDDP.call('updateDoc', docId, newData) the this.userId value prints out null in the Alpha logs. I assumed that when I connect with DDP.connect it would authenticate the connection. However this doesn't seem to be the case. After googling I came across Meteor.call("login") but it appears this won't work if the user isn't using email/password to log in. I tried experimenting with the new AccountsClient but couldn't make any headway. Also another caveat is that I need it to work with the accounts SMS login and the accounts need to be created on the 'Bravo' app. Any ideas on how to do this?

1 个答案:

答案 0 :(得分:0)

鉴于您希望两个应用程序共享一些代码和相同的数据库,您应该查看基于包的体系结构。这将允许您将代码拆分为包,并选择性地将相关代码导入每个应用程序。

meteorpatterns.com has a good guide on this approach.