You can on the OnCreateUser
, do something like this.
Accounts.onCreateUser(function(options, user) {
//if there is not users on the database
//we assign the First-User role
if(Meteor.users.find().count() === 0){
user.role = "First-User"
}else{
user.role = "normalUser"
}
return user;
});
Assuming you have the First-user
role. like this.
Meteor.publish("First-User", function () {
var user = Meteor.users.findOne({_id:this.userId});
if (Roles.userIsInRole(user, ["First-User"])) {
return Meteor.users.find({}, {fields: {emails: 1, profile: 1, roles: 1}});
}
this.stop();
return;
});
Remember you should call the onCreateUser
at the top of the createUsers
methods.
Note that the Roles.addUsersToRoles call needs to come after
Accounts.createUser or Accounts.onCreate or else the roles package
won't be able to find the user record (since it hasn't been created
yet)
From README.
Hope this Works.