Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right way of accessing Meteor.users from the client

Tags:

meteor

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.

like image 996
osolmaz Avatar asked Jan 30 '13 11:01

osolmaz


People also ask

What is the meteor user () function for?

The Meteor Accounts system builds on top of the userId support in publish and methods . The core packages add the concept of user documents stored in the database, and additional packages add secure password authentication, integration with third party login services, and a pre-built user interface.

Which of the following user accounts packages are provided by the meteor developer group?

Here's a complete list of login providers for which Meteor actively maintains core packages: Facebook with accounts-facebook. Google with accounts-google. GitHub with accounts-github.


1 Answers

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
      }
    });
  });   
...
}
like image 72
vladimirp Avatar answered Nov 09 '22 12:11

vladimirp