https://github.com/agencypmg/node-trollbridge
A permissions system for NodeJS
https://github.com/agencypmg/node-trollbridge
Last synced: 3 months ago
JSON representation
A permissions system for NodeJS
- Host: GitHub
- URL: https://github.com/agencypmg/node-trollbridge
- Owner: AgencyPMG
- License: mit
- Created: 2014-06-18T03:23:24.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-08-14T04:25:55.000Z (almost 11 years ago)
- Last Synced: 2025-03-14T12:04:59.612Z (3 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.org/package/trollbridge
- Size: 223 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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
```js
var trollbridge = require('trollbridge');
``````js
trollbridge.addStrategies([
trollbridge.PREMADESTRATEGIES.PASSPORT,
require('./myownstrategy')
]);
```
When creating routes, add a middleware for each route you want to secure```js
app.get('/user/edit', trollbridge.shallNotPass('edit_user'), userEditFunct));
```You can also include a locals variable for templating languages
```js
app.use(function(req, res, next) {
res.locals.has_permission = trollbridge.layoutHasPermission(req);
next();
})
```
and then in your template
```html
{% if has_permission('edit_user') %}
Edit User
{% endif %}
```## Creating Strategies
Strategies will throw an error if they are unable to be authenticated.
```js
//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";
}
}
```