0

I have two meteor apps that use the same database, one is a mobile app (primary) and the other is a desktop app.

From the desktop app, I would like to call the remote mobile method to create a listing so that I don't have to duplicate code 'Listing.create'.

I was under the assumption that my logged in Meteor.userId on the desktop app would be transferred while calling the remote mobile method, but this is not true, as it is undefined.

I also have Oauth and Email auth, and there doesn't seem to be an easy way to login using OAuth (logging in via call 'login' works well for passwords).

What's the best way to call the remote method since it fails without being logged in? I suppose I could pass in the userId as a string but that would open the method up to hacking

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)
});
SkinnyGeek1010
  • 536
  • 7
  • 18

1 Answers1

0

Yes. The method is along the same lines as this answer: Authenticating with Meteor via DDP (and SRP?)

The only difference is instead of using ddp-tools you use Meteor.call("login".. instead, matching the parameters to the type of login.

If the login is of a Facebook, or other OAuth login, you would have to use a loginToken instead of the normal username and password.

Community
  • 1
  • 1
Tarang
  • 75,157
  • 39
  • 215
  • 276
  • Thanks! I'll try this out on Mon. From some additional Googling, it seems that once I log into the desktop app, I could I then use `var token = Accounts._storedLoginToken()` and pass it into `Meteor.call("login", {resume: token}, ..` ? – SkinnyGeek1010 Jun 08 '14 at 14:45