0.4.0 • Published 7 years ago

ndx-user-roles v0.4.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

ndx-user-roles

user roles for ndx-framework apps

install with
npm install --save ndx-user-roles

what it does

ndx-user roles adds these methods to ndx.user

ndx.user.addRole(role)

adds a role to the current user
ndx.user.addRole 'agency.admin'

ndx.user.removeRole(role)

removes a role from the current user
ndx.user.removeRole 'agency.admin'

ndx.user.hasRole(role)

checks if a user has a specific role
role can be a string, an array or a function that returns either a string or an array of role names
ndx.user.hasRole 'agency.admin'

ndx.user.hasRole ['superadmin', 'admin']

ndx.user.hasRole ->
  permissions = ndx.database.exec 'SELECT * FROM permissions WHERE userId=? AND agencyId=?', [ndx.user._id, req.body.agencyId]
  if permissions and permissions.length and permissions[0].canDoThisThing
    res.end 'you\'re cool'
  else
    next 'not permitted'
  

ndx-user-roles also upgrades ndx.authenticate() to accept the same arguments as ndx.user.hasRole

ndx.app.get '/api/protected', ndx.authenticate(['superadmin', 'admin']), (req, res, next) ->
  res.end 'you\'re cool'
0.4.0

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago