User "logged out" event trigger?


#1

Hi guys,

I’d like to redirect the user to a specific route “on log-out”.

I tried the packages:
https://atmospherejs.com/digilord/event-hooks


They work, but they are not up to date and throw me a Exception while invoking method 'eventsOnLoggedOut' Error: Did not check() all arguments during call to 'eventsOnLoggedOut.
Seems like none of them have been updated in 2015.

Is there a method in core that I am missing?


Event for when user logs in?
#2

As far as I know, there is no onLogout callback in Meteor (which is a shame). But you can probably use an autorun like this (not tested):

Tracker.autorun(function(c) {
  var userId = Meteor.userId();
  if (c.firstRun)
    return;
  console.log(userId ? 'Log-in' : 'Log-out');
});

#3

How do you logout? If you let the user visit an url like /logout you can just detect it when visiting that url.


#4

I am using standard accounts-password with ian:accounts-ui-bootstrap-3.

I’ll give autorun a try in order to keep it minimalistic. :smile:


#5

@Steve - thanks a lot for the hint.

This works great.

Is there any reason to have if (c.firstRun) in there?

This is what works for me:

// "Logout"-Hook: Manual implementation
Tracker.autorun(function () {
  var userId = Meteor.userId();
  if (!userId) {
    Router.go('/');  // go 'home' on logout
  }
});

#6

well, this redirect even when person is not logged in from start.
but you wanted just in case of logout

Still I dont believe in login/logout redirects. I better display login/logout template on any route which needs it :smiley:


#7

That error is most likely due to the audit-arguments-check package in your project. http://docs.meteor.com/#/full/auditargumentchecks


#8

You can use https://github.com/gwendall/meteor-accounts-helpers.