Reputation: 1196
Meteor.publish(null, function (){
var users = [ Meteor.users.find({})];
email="[email protected]";
if(users == email ){
users = Meteor.this.userId;
Roles.createRole('admin');
Roles.setUserRoles(users, 'admin');
}else{
users = Meteor.this.userId;
Roles.createRole(['']);
Roles.setUserRoles(users,['']);
}
return Meteor.users.find({});
});}
The goal is when creating user there are two user acc one should have admin and the other is normal user without role. But when I sign in with acc who should get admin role I can't do the things I specified for acc with admin role. I'm missing something and I can't figure what, Thank you in advance for any help you can give.
Upvotes: 1
Views: 213
Reputation: 5088
There are multiple mistakes in this code:
Firstly, you are setting users to be equal to an array and then checking if it is equal to a string. This will always return false.
Secondly, Meteor.this.userId
, should be this.userId
instead.
Thirdly, change this line:
var users = [ Meteor.users.find({})];
to either:
var users = Meteor.users.find({}); // users is a cursor
or:
var users = Meteor.users.find({}).fetch(); // users is an array
Upvotes: 1