# What's the best way to catch the login event in plugin on client side?

**URL:** https://meta.discourse.org/t/whats-the-best-way-to-catch-the-login-event-in-plugin-on-client-side/68055
**Category:** Development
**Created:** [Août 15, 2017, 5:10 UTC](https://meta.discourse.org/t/whats-the-best-way-to-catch-the-login-event-in-plugin-on-client-side/68055 "2017-08-15T05:10:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![a9udn9u](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@a9udn9u](https://meta.discourse.org/u/a9udn9u)
#### Post date: [Août 15, 2017, 5:10 UTC](https://meta.discourse.org/t/whats-the-best-way-to-catch-the-login-event-in-plugin-on-client-side/68055/1 "2017-08-15T05:10:42Z")

</div>

My Discourse site is set up as the SSO provider for my WordPress site. Since login / logout on Discourse doesn’t automatically sync to WordPress, I’m writing a Discourse plugin to do that. I found a way to catch the logout event from here: [discourse/app/models/user.rb at b404a4b97c41953cfd35c51b38068338b918831d · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/b404a4b97c41953cfd35c51b38068338b918831d/app/models/user.rb#L909), but the log\_in method below doesn’t publish to message bus, is there a way to catch login event at all?

Another question, during /logout event, I can send an AJAX request to logout in WP, but the AJAX request gets canceled because logout causes a page refresh before the request is completed, is there a way to tell discourse to wait for a Promise/Deferred to complete before proceed?

Thanks!

---

<div class="post-metadata">

### Author: ![a9udn9u](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@a9udn9u](https://meta.discourse.org/u/a9udn9u)
#### Post date: [Août 15, 2017, 7:40 UTC](https://meta.discourse.org/t/whats-the-best-way-to-catch-the-login-event-in-plugin-on-client-side/68055/2 "2017-08-15T19:40:04Z")

</div>

Looks like I can emit events inside of my plugin, using `DiscourseEvent.trigger`, so the event problem is solved, still trying to look for a way to hold the login/logout page refresh so that the requests I made can be completed.

Any input is appreciated.
