Public user profiles

Hi,

I have another question (bombarding today!). Right now I’ve put my user profile information in the Meteor.user.profile fields. So currently I have bio, avatar and cover image in this user sub-array.

In testing, I’ve added several users and the idea is that you go to the user profile page and you’ll see their profile (minus things like email etc). However, let’s say user A wants to view user B’s profile, they only see their own (despite the URL being for user B). It appears this is because using Meteor.users.find or whatever, you can only find your own profile data?

Should I make a separate profiles collection for the user? The issue then is I also want to display the user role, which I’ve added using the alanning:roles package. I suppose I could update the profiles collection when this role changes though.

Here’s my code right now, it could just be me being dumb-dumb:

In the router:

FlowRouter.route('/profile/:username', {
  name: 'publicProfile',
  action: function(params) {
renderMainLayoutWith(<Profile username={params} />);
  }
});

In Profiles.jsx:

getMeteorData() {
  var username = this.props.username;
  return {
    userProfile: Meteor.users.findOne({}, {"username": username })
  }
},

Do I need to subscribe to a publication since right now it’s in the react component? It might be you can only see your own user data from the client hence the issues. If so, what’s the best way to do this? Since I understand how props pass down from the router but not to / from publications.

Thanks,

Korus.

PS. Had to edit a couple of time since I accidentally (somehow) posted early…

By default, any user gets to see their profile, but no other. You will either need a custom publication for the Users collection to override this behaviour, or use a separate collection.

I’d go for the latter, given the comments in the Meteor Guide re profile.

1 Like

Hi @robfallows and thanks for your reply.

Yeah I had this suspicion, so I’m going to go down that road. Shouldn’t be ‘too’ much extra work!

Thanks,

Korus.

1 Like

How did you get on with this? I have a similar problem

Sorry for the slow response, I only received the email this morning telling me I had your reply…

Anyway, what I did was have a separate mongo collection called ‘profiles’ that grabbed their username on signup and generated other content with it such as avatar, website URL etc. In essence, it was separate to their profile entirely (in keeping with Meteor Accounts being only available to the current user) but they could still go in and edit their own profile in the profiles collection.

This was my profiles schema (it was a basic gaming web app):

Profiles = new Mongo.Collection('profiles');

let ProfilesSchema = new SimpleSchema({
  "avatar": {
    type: String,
    label: "User Avatar"
  },
  "bio": {
    type: String,
    label: "User bio"
  },
  "cover": {
    type: String,
    label: "User cover image"
  },
  "createdAt": {
    type: String,
    label: "Date Created"
  },
  "roles": {
    type: String,
    allowedValues: ['Admin', 'Member', 'Trial', 'Guest'],
    label: "Primary Role"
  },
  "secondary": {
    type: String,
    allowedValues: ['Moderator', 'Helper', 'None'],
    label: "Secondary Roles",
    optional: true
  },
  "username": {
    type: String,
    label: "Username"
  },
  "youtube": {
    type: String,
    label: "Youtube URL",
    optional: true
  },
  "twitch": {
    type: String,
    label: "Twitch URL",
    optional: true
  }
});

Profiles.attachSchema( ProfilesSchema );

Hope this helps!