Add Accounts.onLogout

Add Accounts.onLogout to meteor core which corresponds to the already existing Accounts.onLogin and is called after a Meteor.logout() call ends.

2 Likes

http://docs.meteor.com/#/full/meteor_logout

Meteor.logout([callback]) Client
Log the user out.

Arguments
callback Function
Optional callback. Called with no arguments on success, or with a single Error argument on failure.

I have been using this as a pattern for clean ups and custom tasks that need to follow a successful logout event and it has worked out quite okay.

What other use case can we need to have a separate Accounts.onLogout?

That’s valid when I’m the one calling the Meteor.logout function.

I’m using other packages which handle signup/signin/signout for me. That means their code is calling Meteor.logout. I want to be notified when a logout happens, hence the request for onLogout.

Consider this:
Accounts.createUser accepts a callback, and Accounts.onCreateUser exists.
Meteor.loginWith* accepts a callback, and Accounts.onLogin exists.
Meteor.logout accepts a callback, but there is no Accounts.onLogout.

My specific use is with meteorhacks:flow-router which requires me to write my own tracker to monitor login status. With the addition of Accounts.onLogout I can hook into that.

2 Likes

Check this out:

You’ll probably find https://atmospherejs.com/differential/event-hooks useful

Thank you for suggesting a package which has a workaround for this issue. I implemented a solution before posting to the forum. Once I needed this missing function it seemed obvious the core API has this hole we code around, so I wanted to mention it in the forum.

6 Likes

is this in core now?

I don’t think so. I’ve got the same situation. I’m surprised they added onLogin with adding onLogout

1 Like

For such things we used https://github.com/gwendall/meteor-accounts-helpers which was quite helpfully.

Looks like there is an open PR to add an Accounts.onLogout hook.

2 Likes