Reputation: 2425
I'm building a CMS and depending on the user role
they will be able to edit/update/delete/create different areas but filtered by their role
as in, one user with role: 'basic role'
can't delete what the user with role: 'superuser'
can.
What I have at the moment is this:
Collection.allow({
insert: function(userId, collection) {
return Meteor.users.findOne({_id: userId, profile: {role: 'admin'}});
},
update: function(userId, collection, fields, modifier) {
return Meteor.users.findOne({_id: userId, profile: {role: 'admin'}});
},
remove: function(userId, collection) {
return Meteor.users.findOne({_id: userId, profile: {role: 'admin'}});
}
});
QUESTION Is this the right way to validate users roles? Are there better ways? What are the best practices for this?
Thanks!
Upvotes: 0
Views: 228
Reputation: 59
You should take a look at the alanning:roles package. It's quite widely used and even mentioned in the Meteor Docs. In addition to roles, it also supports groups.
Upvotes: 2