List of all users in the collection of users who are not working for the first time with meteor js

I am having a problem listing all users in a user collection. When I take the listing page, only the current registered user data is displayed. But all users become enumerated after updating the page and its beautiful.

On the server side, I have the following publish code

Meteor.publish("userList", function() { var user = Meteor.users.findOne({ _id: this.userId }); if (Roles.userIsInRole(user, ["admin"])) { return Meteor.users.find({}, { fields: { profile_name: 1, emails: 1, roles: 1, contact_info: 1 } }); } this.stop(); return; }); 

Client side

 Meteor.subscribe('userList'); 

In the js template file, I make the following call

 Meteor.users.find(); 

Please help me with this problem. What am I missing here?

+1
source share
1 answer

This sounds like a race condition with a subscription (it runs until the user logs in). I would recommend placing your subscription inside autorun :

 Tracker.autorun(function() { if (Meteor.user()) { Meteor.subscribe('userList'); } }); 

This has the added benefit of not starting a subscription before a user logs in (saves resources).

By the way, I can't think of why you need this.stop() and the end of your publish function.

+3
source

Source: https://habr.com/ru/post/1015283/


All Articles