Connect/Express middleware to validate if a user belongs to a group. Works nicely with passport.
$ npm install --save connect-crew
By default, connect-crew assumes your authentication middleware returns req.user.groups
as an Array. Check path option if you need to change it.
const express = require('express';)
const crew = require('connect-crew');
const passport = require('passport');
app.use(passport.authenticate('local'));
app.get('/maria-hill',
crew('staff'),
(req, res, next) => res.json({ result: true })
);
app.get('/black-widow',
crew(['avenger', 'staff']),
(req, res, next) => res.json({ result: true })
);
const express = require('express';)
const crew = require('connect-crew');
const passport = require('passport');
app.use(passport.authenticate('local'))
app.use(crew('staff'));
Type: string
or array
Groups to validate.
Type: string
Default: user.groups
Groups array path inside req
object.
Type: object
Default: { code: 401, message: 'Unauthorized'}
Error message when user doesn't belong to a group.
crew.options({
path: 'member.crew',
error: {
code: 401,
message: 'You are not welcome'
}
});
Inside the project folder:
npm i
npm start
MIT © Chef's Plate