# bluebird-rbac

> Mongoose Bluebird RBAC implementation

Latest version **0.0.3** (published 2016-08-24) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install bluebird-rbac
pnpm add bluebird-rbac
yarn add bluebird-rbac
bun add bluebird-rbac
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2016-08-24 |
| First published | 2016-08-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Martijn Klene |
| Maintainers | mtijn |
| Keywords | node, mongoose, bluebird, rbac |

## Links

- npm: https://www.npmjs.com/package/bluebird-rbac
- Repository: https://github.com/MTijn/bluebird-rbac
- Issues: https://github.com/MTijn/bluebird-rbac/issues
- npm.io page: https://npm.io/package/bluebird-rbac

## Dependencies (2)

- [bluebird](https://npm.io/package/bluebird.md) ^3.4.1
- [mongoose](https://npm.io/package/mongoose.md) ^4.5.8

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2016-08-24
- 0.0.2 — 2016-08-24

## README

# Bluebird RBAC

Role based access control that uses Mongoose and Bluebird promises. I have created the library since I was not able to
work with the available libraries on GitHub.

## Requirements

- Mongoose
- Bluebird
- A user model

## Installation
To install from NPM use:
```
npm install bluebird-rbac
```

U have to register the RBAC plugin to the User model. This is achieved by:

```js
var mongoose = require('mongoose');
var rbac = require('bluebird-rbac').rbac;

var UserSchema = mongoose.Schema({
  // ... Any additional fields
});
 
UserSchema.plugin(rbac.plugin);
 
module.exports = mongoose.model('User', UserSchema);
```

## API

### User
#### hasRole(role, done)
Checks if the user has the specified role.

#### addRole(role, done)
Adds the role to the user.

#### removeRole(role, done)
Remove the role from the user

#### can(action, subject, done)
Is the user allowed to perform the action.

#### hasPermissions()
Will return all the permissions the user has.

## Express middleware
You will be able to check for permissions on the routes from express.

```js
var rbac = require('bluebird-rbac');

router.get('/', rbac.userCanAccess({action: 'view', resource: 'user', redirectTo: '/'}), function(req, res, next) {
    // Do stuff in my route.
});
```
If the user does not have the permission, the user will be redirected to /, if redirectTo is not defined
the user will be returned to the last page he visited.

---
_Source: https://npm.io/package/bluebird-rbac · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
