Create public profiles for users

Hi .
I want to create a profile page for all users. Where you can share users’ general information.

In the following code, I get the user username and try to share its general information:

const ProfileSection = withTracker(({ userName }) => {
    const handle = (Meteor.isClient) ? Meteor.subscribe('Pages.Profile', userName) : { ready: () => true };
    const loading = !handle.ready();
    const data = Meteor.users.findOne({ username: userName }, {fields: {username:0 ,services:0,"profile.Type":0 ,"profile.PhoneNumber":0 }});
    return {

And I published the user information with the following code :

Meteor.publish('Pages.Profile', function (userName) {
    const user = Meteor.users.findOne({ username: userName });
    if (!user) {
        throw new Meteor.Error('Not Found');
    return Meteor.users.find({_id: user._id} , {limit:1,fields: {username:0 ,services:0,"profile.Type":0 ,"profile.PhoneNumber":0 }});


But the problem is, no data is shared, and this is the problem when a user is logged in.
I guess it 's because I’re getting two users, one is a logged in user, the other is a user I’m trying to subscribe to.
How do I solve the problem?

When accessing the subscription on the client side you need to filter out the logged-in user, which is always in the subscription (merge-box).

1 Like

Well, I only subscribed to the user whose username I entered, and as a rule I just have to subscribe to the same.
And of course, it should only return the same user to my subscription.
@jamgold However, how can I filter it, I will be grateful if you send a sample code.

some comments:
On line 2 of your first code you have Meteor.isClient and this code runs on the client. In what conditions could this return false?
Do you use withTracker inside a React Container?
In the Publish side, if you don’t find a user, normally you return an empty object or a null. I am not sure you need to throw an error cause this is not an error. In this case, your function becomes one liner with only the return ...
In Subscription you find for one while in publication you find for many. The result of your Subscription should be an object while you publish an array. I am not sure that is ok but I might be wrong.

1 Like

Hi, i don’t know if it can help you but …
Be carrefull when you filter subfield with multiplie publish, only top-level fields are merged

1 Like