How can I check in my website if the user is logged in to my Discourse?

I am building a desktop application, with accompanying forum (running Discourse, of course) and website.

On our website, I would like to show some extra information if the website visitor is also logged in to the forum.

I figured out how to login from the website or desktop application (see this post) , but what I cannot find is a way to check if my website visitor is logged in (and if so, who he is), without actually asking them to login.

Is there a way to do that, e.g. using the Discourse API?

1 Like

i think you may need to get the user ID from the SSO payload and then use a Discourse API request get the username and current login status.

If the user logs in on the forum website, then how can I later get the SSO payload? I know how to get it when I initiate the login myself (by generating a link {forum_url}/session/sso_provider?sso=... etc), but when the user initiates the login, then I have no idea how I could get the SSO payload.

That should indeed be possible, although the exact URL for the API request doesn’t seem to be documented in https://docs.discourse.org. What would be the correct URL?

1 Like

i’m not sure but i suspect you need to access the user_auth_token from the json data of the payload? just a guess to give you ideas. perhaps someone who knows more about Discourse connect SSO can help you.