Is there any way to get info of current logged in user on Discourse from my react SPA without page reload?
AI-generated summary
In a discussion about retrieving the currently logged-in user’s information from Discourse in a React SPA without a page reload, Farhan_Hossen initially seeks a direct API method, but encounters 404 errors when calling /session/current.json from outside the Discourse domain. Arkshine clarifies that the endpoint only works if the user is authenticated in Discourse, which isn’t automatically shared with external sites—even if they’re in the same browser. Firepup650 explains that this is intentional for security: the React app cannot access Discourse’s session credentials directly. The recommended solution is to use Discourse Connect for SSO, but Farhan_Hossen notes this requires a full page reload, which breaks his desired UX for allowing users to create topics from his React app without re-authenticating. pfaffman and Firepup650 both suggest that direct client-side access without SSO is not feasible or secure. Farhan_Hossen confirms he uses server components for sensitive operations, acknowledging the security constraints. In short: cross-site session access without SSO is blocked for security; SSO is the proper path, though it may require architectural adjustments to avoid page reloads.
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.
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.

