Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

Detect user logging in and out on Meteor.users update hooks #98

Closed rclai closed 9 years ago

rclai commented 9 years ago

If I create an update hook on the Meteor.users collection, there doesn't seem to be a nice way to check whether the user is logging in or logging out, except that when logging in, userId is empty and when logging out, the userId is still there and all you have is a modifier that is pulling a loginToken out of the user document and that's it.

Is there a way to expose some kind of this.loggingIn/this.loggingOut flag inside the hook?

mizzao commented 9 years ago

I think this use case is why I created https://github.com/mizzao/meteor-user-status.

Determining when a user has logged out is tricky, and I don't think it's the job of this package to do that.

rclai commented 9 years ago

Yes, but my use case is that of using an update hook on Meteor.users to do something when someone has updated their user profile.

mizzao commented 9 years ago

What does that have to do with logging in/out?

rclai commented 9 years ago

When someone logs in or out, the same update hook gets triggered when I'm updating a user profile. Does that make sense?

mizzao commented 9 years ago

There are all kinds of other existing user collection operations that would also trigger your hook aside from logging out, including changing passwords, pulling expired login tokens, etc.

Rather than trying to put some specific functionality in this package, it seems like your best bet is to check if a particular update is acting on the profile field and to then take an appropriate action.

Better yet, you might want to use observeChanges on a livedata query that includes profile and use the callbacks provided. You don't even need hooks for that.

rclai commented 9 years ago

Okay, I'll manage. Thanks.