How to add roles to user in MeteorJS Meteor JS 21.01.2016

Via meteor-roles you can add roles to meteor's account system.

Add one of the built-in accounts packages so the Meteor.users collection exists. From a command prompt

meteor add accounts-password

Add this package to your project. From a command prompt

meteor add alanning:roles

Add user

# meteor shell
Accounts.createUser({username:"", email : "user@email.com", password: "1"})

Add user some role

# meteor shell
Roles.addUsersToRoles(userId, ['admin'])

# mongo db
db.users.update({_id: "USERID"}, {$set: {roles: ['admin']}})

Check for role

# meteor shell
Roles.userIsInRole(userId, 'admin')

# template
{{#if isInRole 'admin'}}
some action
{{/if}}

# mongo db
db.users.find({_id: "USERID"}).pretty()