osolmaz
osolmaz

Reputation: 1923

Right way of accessing Meteor.users from the client

I have defined some useful fields in the users collection for my convenience. What would be the right way of allowing a client to access the corresponding field? I'm using the autopublish package, but Meteor.user() from the client side only reveals the emails array.

Upvotes: 7

Views: 3173

Answers (1)

vladimirp
vladimirp

Reputation: 1554

You have to explicitly tell Meteor which fields from users to include when querying users collection.

For example to publish custom "avatar" field on client:

// Client only code
if (Meteor.isClient) {

Meteor.subscribe("currentUserData");
...
} 

// Server-only code
if (Meteor.isServer) {

  Meteor.publish("currentUserData", function() {
    return Meteor.users.find({}, {
      fields : {
        'avatar' : 1
      }
    });
  });   
...
}

Upvotes: 7

Related Questions