I have a members table in my application’s database, where I store application-specific information about a subset of members. One of the columns is discourse_user_id. I’d like to render a link to the member’s discourse profile. Is it possible to do that with just their user id?
I am not storing discourse_user_name because the user can change that, and then I’d have to worry about keeping them in sync.
The only way I can think of is to make an API request to /admin/users/<user-id>.json to get their username, but that would be a large number of requests to do on an index page, where I’m listing members with links to their profile.
The only other thing that comes to mind is to build a plugin to add a route, though that seems like a lot of effort for something that I’d expect I’m not the first person to ask about, so I wanted to check whether there’s another solution already?
One idea is to put an external ID in the user record and then you could use /by-external/:external_id. The other is to use a webhook to notify your external database if they change their username. Another is to just disable changing usernames. From a quick look at discourse/config/routes.db I don’t see any route that uses the user_id.
Poking around the API docs and a REST client, though, I don’t see how to update that field. Can I use that without enabling SSO? (And, even if I enabled SSO, would I be able to update it programmatically?)