lyowmg
Last Updated: February 25, 2016
·
9.239K
· benjaminrh
2aca501921a5a98762cc4af16da258b8

Meteor user login/logout hooks!

It's time. The time we've all been waiting for. That's right, it's Mort Fun Time! Free pots of nerd-cred to anybody who doesn't need the link to know what I'm talking about :)

Seriously though, I've been wanting hooks for when a user logs in/out for a while now, as have a number of other Meteorites. It's been mentioned before, and people have recommended different things all over the place. I filed one too the other day.

Since I'm making a package of hooks for various events (I posted that before, but decided this part deserved it's own little post, since so many people have been asking me about it), this seems like a very logical thing to include. Also I'm not very patient. So:

Hooks.onLoggedIn = function () {
    // this runs right after a user logs in, on the client or server
}
Hooks.onLoggedOut = function () {
    // this runs right after a user logs out, on the client or server
}

Also, because some people want to do logout things when a user exits the browser, I've added an option that allows you to fire the onLoggedOut when onCloseSession is triggered.

Hooks.treatCloseAsLogout = true; // somewhere on the client

You can install it with mrt add event-hooks. You can also check out the source (see what I did there?).

Say Thanks
Respond

3 Responses
Add your response

10839

This is awesome, thank you.

over 1 year ago ·
12755
0046aa1cdc7ac0f9c98fcc92644b03f0

Ah, many thanks for making this!

over 1 year ago ·
20080
None

if i want to add a hook right before a user logs in, what should i do?

over 1 year ago ·