# @jermysu/koa-auth-middleware

> `koa-auth-middleware` is a koa middleware for handling authentication by using JWT

Latest version **1.0.0** (published 2018-02-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jermysu/koa-auth-middleware
pnpm add @jermysu/koa-auth-middleware
yarn add @jermysu/koa-auth-middleware
bun add @jermysu/koa-auth-middleware
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-02-13 |
| First published | 2018-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Author | jermysu |
| Maintainers | jermysu |

## Links

- npm: https://www.npmjs.com/package/@jermysu/koa-auth-middleware
- npm.io page: https://npm.io/package/@jermysu/koa-auth-middleware

## Dependencies (3)

- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.1.1
- [randomstring](https://npm.io/package/randomstring.md) ^1.1.5
- [standard-http-error](https://npm.io/package/standard-http-error.md) ^2.0.1

## Recent versions

- 1.0.0 (latest) — 2018-02-13

## README

# koa-auth-middleware

`koa-auth-middleware` is a koa middleware for handling authentication by using JWT 

## Usage

### Authorization

```javascript
const Koa = require('Koa')
const Router = require('koa-router')

const { middleware } = require('koa-auth-middleware')

const app = new Koa()
const router = new Router()

/*All api route api/path will be require a jwt for authorization*/ 
router.use('api/path/', middleware)

app.use(router.routes())

app.listen(3000)
```
### Request

You should apply JWT into `Authorization` header in api route which is `api/path/`


### Generate JWT

```javascript
const { authHeaderGenerator } = require('koa-auth-middleware')

/* Custom playoad to save in JWT */
const playload = {
  userId: 1,
  date: '2018-02-01'
  }

/* Default timeout is for 5 hours */
/* Auth secret will be auto-generated */
const jwt = authHeaderGenerator(playload, options = { expiresIn: '5 h' })
```

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