# auth-jwt

> Biblioteca de autenticação simples via JWT

Latest version **1.0.6** (published 2020-05-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install auth-jwt
pnpm add auth-jwt
yarn add auth-jwt
bun add auth-jwt
```

## 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.6 |
| Published | 2020-05-26 |
| First published | 2016-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6.0.0 |
| Dependencies | 1 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Wallace Silva |
| Maintainers | jovemnf |
| Keywords | JSON, JWT, Autenticate, Token, Web, Bearer |

## Links

- npm: https://www.npmjs.com/package/auth-jwt
- Repository: https://github.com/jovemnf/auth-jwt
- Homepage: https://github.com/jovemnf/auth-jwt#readme
- Issues: https://github.com/jovemnf/auth-jwt/issues
- npm.io page: https://npm.io/package/auth-jwt

## Dependencies (1)

- [jwt-simple](https://npm.io/package/jwt-simple.md) 0.5.6

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.6 (latest) — 2020-05-26
- 1.0.5 — 2020-05-26
- 1.0.4 — 2020-05-26
- 1.0.3 — 2020-03-27
- 1.0.2 — 2018-01-21
- 1.0.1 — 2017-12-30
- 1.0.0 — 2017-05-22
- 0.0.10 — 2017-05-08
- 0.0.9 — 2016-07-11
- 0.0.8 — 2016-06-20
- 0.0.7 — 2016-02-07
- 0.0.6 — 2016-02-07
- 0.0.5 — 2016-02-05
- 0.0.4 — 2016-02-05
- 0.0.3 — 2016-02-05
- … 2 more at https://npm.io/package/auth-jwt/versions

## README

# auth-jwt

> An authentication module using JWT

## Install

    npm install auth-jwt

## Usage

### Example

auth.js

```js
const auth = require('auth-jwt');

let auth = (req, res, next) => {
    auth.verify(req, 'secretKey')
        .then((user)=>{
            req.user = user;
            next()
        })
        .catch((e) => res.sendStatus(401) )
}

app.get('/user', auth, (req, res) => {
    ...
})
```

routes.js
```js
app.get('/user', auth, (req, res) => {
    ...
})
```

### Include the JWT or Bearer in requests

Include the token created by JWT in the request header

    Authorization: JWT JSON_WEB_TOKEN_STRING.....

or 

    Authorization: Bearer JSON_WEB_TOKEN_STRING.....


### Get token in requests

```js
const auth = require('auth-jwt');

let auth = (req, res, next) => {
    auth.getToken(req)
        .then((user)=>{
            console.log(token);
        })
        .catch((e) => console.log(e) )
}

```

### Async / Await

```js
const auth = require('auth-jwt');

module.exports = async (req, res, next) => {
    try {
        req.user = await auth.verify(req, 'secretKey');
        next();
    } catch {
        res.status(401).json({code: 401});
    }
}

```

## Tests

    npm install
    npm test

## License

The [MIT License](http://opensource.org/licenses/MIT)

Copyright (c) 2016 Wallace Silva

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