# access-roles

> # HOW TO INSTALL ?

Latest version **1.0.3** (published 2018-05-26) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install access-roles
pnpm add access-roles
yarn add access-roles
bun add access-roles
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-05-26 |
| First published | 2018-04-30 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 41.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ayoub AMINE |
| Maintainers | ayoubamine |
| Keywords | access, access-control, role, grant, deny, allow, reject, permission, possession, express, admin, user, glob, policy |

## Links

- npm: https://www.npmjs.com/package/access-roles
- Repository: https://github.com/ayoubamine/access-roles
- Homepage: https://github.com/ayoubamine/access-roles#readme
- Issues: https://github.com/ayoubamine/access-roles/issues
- npm.io page: https://npm.io/package/access-roles

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2018-05-26
- 1.0.2 — 2018-05-26
- 1.0.1 — 2018-05-26
- 1.0.0 — 2018-04-30

## README

# Node ACCESS ROLES

# HOW TO INSTALL ?

```javascript
npm install --save access-roles
```

# HOW TO USE ?

```javascript
var accessRoles = require('access-roles')(app);
```

## accessRoles(options, callback)

Create a new accessRoles middleware function using the given **options** object and **callback** function.

**options**

- **roles (Required)**
Filename contains roles array:
    - **path** (Required): Handled by express.
    - **methods** (Default: ['GET']): HTTP methods array.
    - **permissions** (Required): Permissions allowed.
    - **redirect** Redirect a request, handled by express.

- **dataSource (Required)**
Object in req contains user info.

- **onSuccess**
Response on success.

- **onFailed**
Response on failed (Default: { status: 401, message: 'Not Authorized' }).

- **beforeEnter**
Called before enter.

- **callback**
The callback(err[name, message]).

Example

```json
{
    "roles": [
        {
            "path": "/",
            "methods": ["GET"],
            "permissions": ["Admin"],
            "redirect": "/home"
        }
    ]
}
```

```javascript
function onSuccess(req, res, next) {
	// ...
}

function onFailed(req, res, next) {
	// ...
}

function beforeEnter(req, res, next) {
	// req.userData = ...;
}

var options = {
    roles: './config/roles.json',
    dataSource: 'userData',
    onSuccess: onSuccess,
    onFailed: onFailed,
    beforeEnter: beforeEnter
};
```

```javascript
accessRoles(options, (err) => {
	if (err) throw err;
});
```

# TODO

- Tests
- Give me suggestions ??

# LICENSE

GPL-3.0

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