1.1.1 • Published 5 years ago

role-required-express v1.1.1

Weekly downloads
2
License
LGPL-3.0
Repository
github
Last release
5 years ago

Role required middleware

A simple Express middleware to check roles in the session.

Usage

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).