# connect-crew

> Connect/Express middleware to validate if a user belongs to a group.

Latest version **0.0.1** (published 2016-02-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install connect-crew
pnpm add connect-crew
yarn add connect-crew
bun add connect-crew
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2016-02-29 |
| First published | 2016-02-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Helder Santana |
| Maintainers | chefsplate |
| Keywords | connect, express, passport, groups, user, permission, authentication, authenticate, auth, acl |

## Links

- npm: https://www.npmjs.com/package/connect-crew
- Repository: https://github.com/chefsplate/connect-crew
- Homepage: https://github.com/chefsplate/connect-crew#readme
- Issues: https://github.com/chefsplate/connect-crew/issues
- npm.io page: https://npm.io/package/connect-crew

## Dependencies (1)

- [dot-prop](https://npm.io/package/dot-prop.md) ^2.3.0

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 0.0.1 (latest) — 2016-02-29

## README

# connect-crew [![Build Status](https://travis-ci.org/chefsplate/connect-crew.svg?branch=master)](https://travis-ci.org/chefsplate/connect-crew)

> [Connect](http://www.senchalabs.org/connect/)/[Express](http://expressjs.com/) middleware to validate if a user belongs to a group. Works nicely with [passport](http://passportjs.org/).


## Install

```
$ npm install --save connect-crew
```

### Requirements
* [Connect](http://www.senchalabs.org/connect/) or [Express](http://expressjs.com/)
* Node.js 4+
* An authentication middleware like [passport](http://passportjs.org/)

## Usage

By default, **connect-crew** assumes your authentication middleware returns ``req.user.groups`` as an **Array**. Check [path option](#path) if you need to change it.

### Single request

```js
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

```js
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`<br>
Default: `user.groups`

Groups array path inside `req` object.

##### error

Type: `object`<br>
Default: `{ code: 401, message: 'Unauthorized'}`

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

#### Default options

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

## Develop
Inside the project folder:

```shell
npm i
npm start
```

## License

MIT © [Chef's Plate](http://chefsplate.com)

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