belisarius222 / meteor-event-horizon

reactive event system for Meteor
15 stars 5 forks source link

Compatiblity #1

Open Tarang opened 11 years ago

Tarang commented 11 years ago

Wonderful package @belisarius222!! I particularly find good use with the loggedIn event. I had to previously write an adequately long check.

Is it possible to have this loggedIn/loggedOut event on the server?

belisarius222 commented 11 years ago

Thanks, glad to hear it's useful!

I don't think this package will work on the server, since Deps is only defined client-side.

What I'd recommend to get the server to do something when a user logs in would be to have the client call a server-side method like so:

// client
EventHorizon.on('loggedIn',function(){ Meteor.call('onLogin'); });

// server
Meteor.methods({
  onLogin: function() {
    console.log('user logged in: '+this.userId);
  }
});

Would that work?

On Thu, Mar 21, 2013 at 12:46 AM, Tarangp notifications@github.com wrote:

Wonderful package @belisarius222 https://github.com/belisarius222!! I particularly find good use with the loggedIn event. I had to previously write an adequately long check.

Is it possible to have this loggedIn/loggedOut event on the server?

— Reply to this email directly or view it on GitHubhttps://github.com/belisarius222/meteor-event-horizon/issues/1 .

Tarang commented 11 years ago

I'm using that at the moment, the trouble is the logout method. I can't use accounts-ui without modifying it because I have to employ a callback from Meteor.call to logout on the client. If I Meteor.call after logging out meteor won't be able to tell which user it was

belisarius222 commented 11 years ago

Hmm, you could maybe store the userId in a variable while logged in, like Meteor.previousUserId or something, and then when you get a loggedOut event on the client, run Meteor.call('onLogout',Meteor.previousUserId);

Not sure about the security implications of that approach.

On Thu, Mar 21, 2013 at 9:52 PM, Tarangp notifications@github.com wrote:

I'm using that at the moment, the trouble is the logout method. I can't use accounts-ui without modifying it because I have to employ a callback from Meteor.call to logout on the client. If I Meteor.call after logging out meteor won't be able to tell which user it was

— Reply to this email directly or view it on GitHubhttps://github.com/belisarius222/meteor-event-horizon/issues/1#issuecomment-15281198 .

ghost commented 11 years ago

Ah I see now. That is how I am making the call to the server. I wonder if it's possible to make EventHorizon work on server side as well?

It would be nice to have some sort of interface between the two that is hidden to the developer's eyes. But I guess this is not necessary as Meteor.call() is essentially same. The beauty of this would be you wouldn't have to have to expose all the Meteor.methods.

client.js EventHorizon.fire{'loggedin'}

server/events.js EventHorizon.on{'loggedIn', handleUser};

Tarang commented 11 years ago

@belisarius222 this is tricky because I would be able to trick the onLogOut method on the server with a random userId & not be able to verify its legitimate so it poses a bit of a security risk. I have meteor connecting to facebook's xmpp servers & I want to be able to tell them to log out, for now I'm using a callback & waiting to disconnect first.