Discourse API: Current user


(Pablo Neirotti) #1

Hi there!

With time, I’ve been making my website and it’s forum become more like one. In example, when an article is published, it creates a Discourse thread, and all comments post in there, show up as the comment section of the article on the website. Unification! :smiley:

Now I wanted to bring more of the user profile into the website, but I can’t figure out if there is a way, with the Discourse API, to check the current logged in user. So I can show the Avatar, their badge, and so on.

Is there any way to do this?

Thank you for your time and for making the best forum software to date.


(Kane York) #2

You want /session/current.json. I’m not sure what the CORS rules are on this, though…


(Pablo Neirotti) #3

Ah, I was looking at the Discourse API gem, which doesn’t seem to do everything the API can do. I’ll check that out, thanks for the tip.

Edit: Apparently I can just make a call and will throw the current user, but I am sure that won’t work if I request it from server side…

If I wanted to do this, I would have to use cross-site cookies or something like that, right?


(Kane York) #4

You could also use SSO to have accounts on both websites.

[quote=“PabloNeirotti, post:3, topic:31639”]
Edit: Apparently I can just make a call and will throw the current user, but I am sure that won’t work if I request it from server side…

If I wanted to do this, I would have to use cross-site cookies or something like that, right?
[/quote]Yes, you would have to do everything from JS and have nginx add an Access-Control-Allow-Origin: www.mysite.com header.


(Pablo Neirotti) #5

Ah I see! Thank you for your help :smile:

I’ll investigate more on SSO first though…