# cupcoffee-auth-jwt

> JWT authentication to CupcoffeeJs

Latest version **0.1.4** (published 2016-08-05) · ISC license · 0 weekly downloads

## Install

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

## 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.1.4 |
| Published | 2016-08-05 |
| First published | 2016-08-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Philippe Assis |
| Maintainers | philippeassis |
| Keywords | cupcoffee, jwt, token, auth |

## Links

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

## 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.1.4 (latest) — 2016-08-05
- 0.1.3 — 2016-08-03
- 0.1.2 — 2016-08-03
- 0.1.1 — 2016-08-03

## README

# cupcoffee-auth-jwt
JWT authentication to CupcoffeeJs

## Install

Create environment variable: NODE_CUPCOFFEE_JWT_SECRET or NODE_JWT_SECRET with secret code to JWT.
Example:
`NODE_CUPCOFFEE_JWT_SECRET=MY.SCRET.CODE.TO.JWT`

Or manually add to `require('cupcoffee-auth-jwt')('MY.SCRET.CODE.TO.JWT')`

##Middware

middware/index.js
```javascript
var cupJwt = require('cupcoffee-auth-jwt')()

module.exports = () => {

    this.express = () => {
        return cupJwt.middware('/api/*', ({req, res, next}) => {
           //Success callback
            return next()
        })
    }

    return this;

}

```

## Routes
routes/index.js
```javascript
var cupJwt = require('cupcoffee-auth-jwt')()

module.exports = ({router, controller}) => {

    router.post('/login', cupJwt.validate((user, pass, next) => {
        //.. User authentication, return false or data user
        var result = { email: "user@email.com"}
        next(result)
    }).login);

    router.get('/api/*', (req, res) => {
        controller.http(req, res).find();
    })

    return router;
};
```

## Token
In the HTML header to send `x-access-token` with the token and `x-key` with the username;

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