How to call a function when hitting /login and already logged in

I’ve got a thinkific plugin that logs into thinkific when a user logs in to Discourse. If a user tries to log in to thinkific (and thinkific is so configured) they are redirected to Discourse. If they are not logged in to Discourse, when they log in, a jwt payload is sent to thinkific and logs them in. There was much rejoicing.

The problem is that if they quit the browser they get logged out of Thinkific, but not discourse. Right now, the code that sends the JWT to thinkific happens only at login, so in order to log in to Thinkific they have to log out and back in to Discourse.

What (I think) I want to happen is if the user hits /login and is already logged in I still generate the jwt call to Thinkific. But I can’t figure how how to do that.

Do I change something here?

https://github.com/pfaffman/discourse-thinkific/blob/master/plugin.rb#L37-L40

Or maybe change something with the session controller?

Or maybe something here?

https://github.com/pfaffman/discourse-thinkific/blob/master/assets/javascripts/initializers/discourse-thinkific.js.es6

I don’t quite know where to look.

2 Likes

Can anyone give me a hint on how I can get some code triggered when hitting /login and already logged in?