7

Using this package in MeteorJS accounts-google, I was trying to find the right approach to have a callback after user login & logout. Currently I am using below hook for login (which seems to me too simplistic -- i want to find a hook that triggered by callback after successful authentication) ~ and still not sure how to do for logout.

Meteor.autorun(function() { if (Meteor.user()) { //code for login } }

iwan
  • 7,269
  • 18
  • 48
  • 66
  • one solution here using iron-router and Meteor.user()/Meteor.loggingIn(): http://stackoverflow.com/questions/22900405/how-to-redirect-after-user-has-just-logged-in-or-just-logged-out?answertab=votes#tab-top – dm76 Sep 22 '14 at 09:42

1 Answers1

9

UPDATE: There is now an onLogout hook


From what I have seen, there are no hooks for the logged out event, but there is one for logged in event:

Accounts.onLogin(func)

The event-hooks package adds an onLoggedOut hook.

You could also do something like this:

Meteor.autorun(function () {
  if (Meteor.userId()) {
    do something when logged in
  } else {
    do something when logged out
  }
});
flynfish
  • 5,857
  • 3
  • 24
  • 33