Can users make their User ID visible on their profile?

Is there a way for users to see their own User ID when someone views their profile?

Right now, IDs are only visible to admins through the dashboard, but I’d like users to be able to display their ID publicly.

Is this something that can be enabled through admin settings, a component, or a plugin?
Let me know! Please

לייק 1

It should be doable in a theme component. The user ID is available without an additional request, so you’d only need some JavaScript to show it in a plugin outlet on the profile page.

3 לייקים

What’s the use case? Why is knowing a random integer important?

4 לייקים

@pfaffman Thanks for the reply. Well, because a UID is immutable (never changes) it can act like a permanent fingerprint for someone’s account. Usernames can change so for support tickets it instantly can find their account, transactions, auth sessions etc… UID cannot be faked and are unique forever.
I would like the UID to increment by 1 with every new users

@Moin Thanks for the reply it was helpful. Yesd I can view the response in Network → XHR → Response. Perfect. But I am unaware as to how to show the UID on the users account profile. I want to display it here: https://mydomain.com/u//preferences/account
But within the create components there is only these options: , Before Header, After Header and Footer

This is ultimately what I would like.

I have got the UID to display with some JS but its only showing on the header of the main page

/my/preferences/account is not public; other users cannot see that, but based on your use case, it might be enough for the user themselves to see their ID.

You need to find a plugin outlet that is close to where you want to show the information. I usually use the button in the developer toolbar to make them visible on a forum. Seeing them within the forum makes it easier for me to find the best outlet. You can find more information on how to show something in an outlet in the Theme Developer Tutorial: 1. Introduction

Okay so if I want everyone to see it (public) I would place it within: mydomain.com/u/<user>summary
So by use of enableDevTools() within the browser console I think user-profile-secondary will be a good place.
I will try now.

Im stuck. How would I get the id of the user I am viewing? Because api.getCurrentUser does the logged in user.

I just put the User ID on plugin outlet: header-contents__after

לייק 1

Custom Components -- add button or text at any plugin outlet is an example of how to stick some text anywhere that there’s a plugin outlet. I think you’ll need to create your own theme component to get access to the user_id.

I think you’d do something like this when you call your component:

        <YourIdComponent
          @user={{@user}}
        />
לייק 1

But how do I get the user.id of someone else using code.

Using @pfaffman 's post above, you can then have a component that uses {{@user.id}}. See Theme Developer Tutorial: 5. Building and using components, but I think you can do it in Edit CSS/HTML > JS in the Discourse TC UI, using api.renderInOutlet().

3 לייקים

Yes api.renderInOutlet() came in clutch. However my issue which is now irrelevant since I approached it differently—was that I didn’t know how to retrieve the user.id of the profile being viewed.
Got any ideas?

Here’s the answer, but it sounds like you don’t have the background to understand it.

לייק 1

I think it would be easier if you chose an outlet that provides the model of the user whose page you are viewing.

The outlet you chose offers information about the topic but not about users


The outlets on the user profile like user-post-names provide the user model:

With an outlet that provides the model you should be able to use @outletArgs like the example in Theme Developer Tutorial: 4. Using Outlets to insert and replace content. The example there uses discovery-list-container-top which provides @outletArgs={{lazyHash category=@model.category tag=@model.tag}}

That’s why I would choose an outlet that provides the user model. You can see the model when you hover over the outlet and see the ID of the user whose profile you look at. Many examples in the tutorial use the currentUser service, which provides the ID of the acting user, which is not what you seem to be looking for.

לייק 1
import { apiInitializer } from "discourse/lib/api";

export default apiInitializer((api) => {
    
    api.renderInOutlet("user-post-names",
    <template>
        {{#if @outletArgs.model}}
            <div class="uid-label-profile">
                UID:
                <span class="uid-value-profile">
                {{ @outletArgs.model.id }}
                </span>
            </div>
        {{/if}}
    </template>
    );

});

@Moin your breakdown was spot on — just followed it and everything works flawlessly now. Thank you.

3 לייקים