# @3merge/express-auth-middleware

> Authentication middleware for Express APIs

Latest version **1.0.4** (published 2019-09-18) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @3merge/express-auth-middleware
pnpm add @3merge/express-auth-middleware
yarn add @3merge/express-auth-middleware
bun add @3merge/express-auth-middleware
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-09-18 |
| First published | 2019-09-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 16 |
| Unpacked size | 58.9 KB |
| Known vulnerabilities | 0 (+10 in 3 direct dependencies) |
| Install scripts | no |
| Author | Mike |
| Maintainers | 3merge |

## Links

- npm: https://www.npmjs.com/package/@3merge/express-auth-middleware
- Repository: https://github.com/3merge/express-auth-middleware
- npm.io page: https://npm.io/package/@3merge/express-auth-middleware

## Dependencies (16)

- [flat](https://npm.io/package/flat.md) ^4.1.0
- [bcrypt](https://npm.io/package/bcrypt.md) ^3.0.6
- [crypto](https://npm.io/package/crypto.md) ^1.0.1
- [dotenv](https://npm.io/package/dotenv.md) ^8.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [moment](https://npm.io/package/moment.md) ^2.24.0
- [connect](https://npm.io/package/connect.md) ^3.7.0
- [express](https://npm.io/package/express.md) ^4.17.1
- [mongoose](https://npm.io/package/mongoose.md) ^5.7.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1
- [request-context](https://npm.io/package/request-context.md) ^2.0.0
- [generate-password](https://npm.io/package/generate-password.md) ^1.4.2
- [mongoose-paginate-v2](https://npm.io/package/mongoose-paginate-v2.md) ^1.3.0
- [express-async-handler](https://npm.io/package/express-async-handler.md) ^1.1.4
- [mongoose-unique-validator](https://npm.io/package/mongoose-unique-validator.md) ^2.0.3

## Recent versions

- 1.0.4 (latest) — 2019-09-18
- 1.0.3 — 2019-09-18
- 1.0.2 — 2019-09-18
- 1.0.1 — 2019-09-18
- 1.0.0 — 2019-09-18

## README

# Authentication middleware

__Work in progress!__

## The user model

Discriminating the user model, the preferred approach, assigns a `kind` property to all documents. I recommend using the decorator functions in this module to get/set properties in the base as well.

### Schema

| Property      | Type       | Description                                                                                  | Default |
| ------------- | ---------- | -------------------------------------------------------------------------------------------- | ------- |
| active        | `boolean`  | System-generated to keep track of "deleted" users                                            | `true`  |
| email*        | `string`   | Self-explanatory                                                                             | `null`  |
| firstName*    | `string`   | Self-explanatory                                                                             | `null`  |
| frozen        | `boolean`  | Somewhat of an alias for active, only setting it does not affect other properties            | `false` |
| lang          | `string`   | The preferred locale (`en-CA` or `fr-CA`).                                                   | `en-CA` |
| lastName*     | `string`   | Self-explanatory                                                                             | `null`  |
| loginAttempts | `number`   | Used to block excessive login attempts (< 5)                                                 | `0`     |
| password      | `password` | Used to authenticate                                                                         | `null`  |
| secret*       | `string`   | Used to read and write JWT tokens. Nullifying this would destroy all active sessions         | `null`  |
| verified      | `boolean`  | Represents the validity of an email address. Login attempts are blocked without verification | `false` |

### Methods

| Name                                        | Description                                                                      | Return    |
| ------------------------------------------- | -------------------------------------------------------------------------------- | --------- |
| `await Model.findByEmail(string)`           | Lookup active users by email address                                             | `object`  |
| `await Model.findUnverifiedByEmail(string)` | Lookup unverified users by email                                                 | `object`  |
| `await Model.findVerifiedByEmail(string)`   | Lookup verified users by email                                                   | `object`  |
| `await Model.findVerifiedById(string)`      | Lookup verified users by id                                                      | `object`  |
| `await doc.setSecret()`                     | Generate secret token                                                            | `object`  |
| `await doc.verifyPassword(string, boolean)` | Compare string against stored password. Throws error if second parameter is true | `boolean` |
| `await doc.deactivate()`                    | Deletes a user for most intents-and-purposes                                     | `object`  |
| `doc.isBlocked`                             | Is the user allowed to login?                                                    | `boolean` |
| `doc.hasExpired`                            | Has more than 24 hours elapsed since requesting verification?                    | `boolean` |
| `doc.isPermitted`                           | Does the user have all the necessary properties to login?                        | `boolean` |

---
_Source: https://npm.io/package/@3merge/express-auth-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
