trollbridge

0.1.3 • Public • Published

node-trollbridge

A permissions system for Node and Express

How to use

include the troll library and setup any of the strategies you want to include.

You can make your own strategy functions or use some of the premade ones

var trollbridge = require('trollbridge');
trollbridge.addStrategies([
   trollbridge.PREMADESTRATEGIES.PASSPORT,
   require('./myownstrategy')
]);

When creating routes, add a middleware for each route you want to secure

app.get('/user/edit', trollbridge.shallNotPass('edit_user'), userEditFunct));

You can also include a locals variable for templating languages

app.use(function(req, res, next) {
    res.locals.has_permission = trollbridge.layoutHasPermission(req);
    next();
})

and then in your template

{% if has_permission('edit_user') %}
<a href="/user/edit">Edit User</a>
{% endif %}

Creating Strategies

Strategies will throw an error if they are unable to be authenticated.

//sample strategy
module.exports = function(req, permission) {
    if (!req.isAuthenticated()) {
        throw "User is not authenticated";
    }
 
    if (typeof req.user === 'undefined' || req.user == null) {
        throw "Should not be able to login";
    }
}

Readme

Keywords

Package Sidebar

Install

npm i trollbridge

Weekly Downloads

4

Version

0.1.3

License

MIT

Last publish

Collaborators

  • evelynli
  • adityachaudhari1412
  • jay-anderson
  • satishns
  • frank.torres
  • aayush1999
  • lrxdtc
  • abdallahhwishel
  • kendrick-mcadams
  • noahwebber
  • srisandhyamaddula
  • artem.polupan.pmg
  • jena
  • andrethio
  • vijayakumarchandrasekar
  • adamdutton08
  • tani-shah
  • jwzhang
  • jrughani
  • sirach99
  • aliciazavala
  • yashodhara
  • keerthi_kamarthi
  • nihitparikh
  • jzhang502
  • jgmpmg
  • psmith22
  • d3vj3rry
  • chrisguitarguy
  • chrisalvares
  • pmgbot
  • emilysnothere
  • eawooten
  • jamiebarbosa
  • ericelsken
  • phildier
  • becconk
  • skyemck
  • siephen
  • ian-evidente
  • hanakim778
  • talinhall
  • niclee521
  • abdullah.alhamoud
  • shlokkhetan
  • harshithamandru
  • diego.pozo