Haikal Nashuha
Haikal Nashuha

Reputation: 3048

Meteor Getting Users CreatedAt and Emails

My app has autopublish turned on.

I want to create a page that shows the lists of the registered users, their emails and when they are created. So I build of the grid from the Meteor.users collection.

I parsed the information like this

{{#each users}}
<ol>
   <li>
      {{username}}
   </li>
   <li> 
      {{emails[0].address}}
   </li>
   <li> 
      {{createdAt}}
   </li>
 </ol>
{{/each}}

However I managed to only get the username. The emails return [Object object] in the grid and the createdAt returns empty.

How can I correctly parse these two fields?

Upvotes: 1

Views: 778

Answers (1)

Tarang
Tarang

Reputation: 75945

Firstly you'll need to publish the user's data yourself. autopublish does do this but it restricts the fields.

Publish the data to yourself with the below, you can use the fields option to explicitly define which fields you would like the client to see. With autopublish these fields are usually just username and profile.

Server side

Meteor.publish("users", function() {
    return Meteor.users.find({}, {fields:{createdAt: true, profile: true, emails: true, username: true}});
});

Client side

Meteor.subscribe("users");

Then you should be able to see .createdAt and the emails too.

For your email you would need to use {{emails.[0].address}} as [] doesn't work in Spacebars/Handlebars like it would in javascript

Upvotes: 2

Related Questions