Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing custom Meteor.user() fields

Tags:

meteor

I know this question has been asked numerous times but I am having a difficult time publishing this information.

In Accounts.onCreateUser I am adding a field like so

{
 ...
 user['info'] = { email: options.email, is_admin: false};
}

I publish this information;

Meteor.publish('user', function() {
    return Meteor.users.find({}, { fields: { info: 1} });
}

and

Meteor.subscribe('user');

After debugging the Publish query returns the correct information but that is never given to the client when I try to access Meteor.user(). Do I have to do something else to allow info to be access by Meteor.user()?

Any suggestions?

like image 830
puttputt Avatar asked Oct 24 '13 16:10

puttputt


1 Answers

You'll want to use null to publish to the single user.

Meteor.publish(null, function() {
  return Meteor.users.find({_id: this.userId}, {fields: {info: 1}});
});
like image 188
Pent Avatar answered Sep 24 '22 01:09

Pent