Skip to content

A simple Express middleware to check roles in the session.

Notifications You must be signed in to change notification settings

uwburn/role-required-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A simple Express middleware to check roles in the session.

Resources

Stars

Watchers

Forks

Packages

No packages published