Is there any way to get info of current logged in user on Discourse from my react SPA without page reload?
Hmm, would /session/current.json
route work here?
I tried sending a get request but it returned 404.
I think you may need discourse connect so that both sites get logged in to the same sso source.
I’m just trying to get the currently logged in username. No need for signing in.
That’s the point. If you are not logged in in Discourse, this route returns a 404.
In another browser where I’m not logged in:
Isn’t that what you want?
It works when I send the API request within my forum. But not from my React website, which is running on the same browser.
Which makes sense, that React site does not have and cannot get the relevant credentials from the forum to make the request, and it shouldn’t be able to get them. That’d be an extreme security issue if it could. I’d recommend doing was was mentioned above and setting up Discourse connect.
I’m already using discourse connect where I allow members of specific group to sign in to my website using discourse.
I do have a composer right in my react app to allow user to create topic directly from my react app without needing to create an account in my react app. So I need to know the user info who is logged in on discourse.
The problem with SSO is that it requires a full page reload which I need to avoid to make my feature work.
I don’t believe that is possible, but perhaps someone else can help you and prove me wrong.
You want to make sure that you’re not making API calls via a javascript front end that has an API key.
Sure, I use server components in such case. Thanks for your suggestion.