I have added roles to my user collections. I'm trying to publish all users collection to admin user only but I'm only getting admin collection being returned currently.
Publish code:
Meteor.publish("users", function() {
let result = [];
if (Roles.userIsInRole(this.userId, ["admin"])) {
result = Meteor.users.find({});
} else {
this.stop();
}
return result;
});
Subscription
Meteor.subscribe("users");
Adding admin:
if (!Meteor.users.find().count()) {
var users = [
{ name: "Johnson Doe", email: "[email protected]", roles: ["admin"] }
];
_.each(users, function(user) {
var id;
id = Accounts.createUser({
email: user.email,
password: "password@123",
profile: { name: user.name }
});
if (user.roles.length > 0) {
Roles.addUsersToRoles(id, user.roles, "default-group");
}
});
}
Is there a way that the admin user can have access to all other user collections?
Roles.addUserToRolesand the publication of your admin collection. - JankapunktRoles.addUsersToRoles(id, user.roles, "default-group");And I'm subscribe like this:Meteor.subscribe("users");Meteor.users.find().fetch()- Israel Z Kollie