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?
Steve
October 17, 2015, 9:25am
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');
});
How do you logout? If you let the user visit an url like /logout you can just detect it when visiting that url.
I am using standard accounts-password
with ian:accounts-ui-bootstrap-3
.
I’ll give autorun a try in order to keep it minimalistic.
@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
}
});
shock
October 17, 2015, 10:59am
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
That error is most likely due to the audit-arguments-check
package in your project. http://docs.meteor.com/#/full/auditargumentchecks