connect-crew

0.0.1 • Public • Published

connect-crew Build Status

Connect/Express middleware to validate if a user belongs to a group. Works nicely with passport.

Install

$ npm install --save connect-crew

Requirements

Usage

By default, connect-crew assumes your authentication middleware returns req.user.groups as an Array. Check path option if you need to change it.

Single request

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 })
);

All requests

const express = require('express';)
const crew = require('connect-crew');
const passport = require('passport');
 
app.use(passport.authenticate('local'))
app.use(crew('staff'));

API

crew(input, [options])

input

Type: string or array

Groups to validate.

options

path

Type: string
Default: user.groups

Groups array path inside req object.

error

Type: object
Default: { code: 401, message: 'Unauthorized'}

Error message when user doesn't belong to a group.

Default options

crew.options({
    path: 'member.crew',
    error: {
        code: 401,
        message: 'You are not welcome'
    }
});

Develop

Inside the project folder:

npm i
npm start

License

MIT © Chef's Plate

Package Sidebar

Install

npm i connect-crew

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • chefsplateca
  • helder