Nacho_Caballero wants to create a post with a dynamic URL that includes the currently logged-in user’s username. pfaffman suggests using a theme component to access the post record’s username, referencing the Developer’s guide to Discourse Themes.
However, Nacho_Caballero clarifies that he wants to query the currently logged-in user’s username in real-time, similar to the /my route. pfaffman confirms that this is possible by accessing current_user, with examples available in the developer’s guide.
I was wondering if it’s possible to create a post that references the username of whoever is logged in? Sort of like the /my route but for the frontend.
My use case would be to customize a URL pointing outside of Discourse so when a user clicks it, it will have the query ?username=MY_USERNAME appended to it. The same approach could be used to embed an iframe with that URL, for example.
If this is not possible out of the box, I assume the other alternative would be to write a custom plugin.
Yes. The post record has the username in it (see https://meta.discourse.org/t/is-there-a-recommended-way-to-get-the-current-username-from-a-post/178288.json).
Oh, well, the particulars are different but the answer is the same. There should be examples in the developer’s guide, so you can see how to access current_user.