# role-required-express

> Express middleware to check roles in the session

Latest version **1.1.1** (published 2019-08-06) · LGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install role-required-express
pnpm add role-required-express
yarn add role-required-express
bun add role-required-express
```

## 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.1.1 |
| Published | 2019-08-06 |
| First published | 2019-08-06 |
| Weekly downloads | 0 |
| License | LGPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Michele Tibaldi |
| Maintainers | uwburn |

## Links

- npm: https://www.npmjs.com/package/role-required-express
- Repository: https://github.com/uwburn/role-required
- Homepage: https://github.com/uwburn/role-required#readme
- Issues: https://github.com/uwburn/role-required/issues
- npm.io page: https://npm.io/package/role-required-express

## Dependencies (1)

- [http-error-prototype](https://npm.io/package/http-error-prototype.md) ^1.0.0

## Recent versions

- 1.1.1 (latest) — 2019-08-06

## README

# Role required middleware

A simple Express middleware to check roles in the session.

### Usage

```javascript
var express = require('express');
var roleRequired = require('role-required');

var router = express.Router();

router.use('/admin', roleRequired({
    errorStatus: 403,
    errorMessage: "Forbidden",
    rolesField: "roles",
    roleRequired: "admin" 
}));
```

### Notes
The middleware will check that `req.session` has a string array named as specified by the `rolesField` option, containing the string identified by the `roleRequired` option. The status, message and rolesField are optional and will default to `403`, `Forbidden` and `roles`. The error generated is an `http-error` and can be dealt by `http-error-express` (see related modules).

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