# egg-full-jwt

> jwt插件

Latest version **1.1.4** (published 2019-07-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-full-jwt
pnpm add egg-full-jwt
yarn add egg-full-jwt
bun add egg-full-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.1.4 |
| Published | 2019-07-08 |
| First published | 2018-11-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 1 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | alex_my@126.com |
| Maintainers | hi.alex.happiness |
| Keywords | egg, eggPlugin, egg-plugin, egg-jwt |

## Links

- npm: https://www.npmjs.com/package/egg-full-jwt
- Repository: https://github.com/alex-my/egg-full-jwt
- Homepage: https://github.com/alex-my/egg-full-jwt#readme
- Issues: https://github.com/alex-my/egg-full-jwt/issues
- npm.io page: https://npm.io/package/egg-full-jwt

## Dependencies (1)

- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@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

## Recent versions

- 1.1.4 (latest) — 2019-07-08
- 1.0.4 — 2018-11-28

## README

# egg-full-jwt

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-full-jwt.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-full-jwt
[travis-image]: https://img.shields.io/travis/eggjs/egg-full-jwt.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-full-jwt
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-full-jwt.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/egg-full-jwt?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-full-jwt.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-full-jwt
[snyk-image]: https://snyk.io/test/npm/egg-full-jwt/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-full-jwt
[download-image]: https://img.shields.io/npm/dm/egg-full-jwt.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-full-jwt

<!--
Description here.
-->

## Chinese 中文

- [点这里](./README.zh_CN.md)

## Important

> jsonwebtoken@8.4.0

## Install

```bash
$ npm i egg-full-jwt --save
```

## Usage

```js
// {app_root}/config/plugin.js
exports.fullJwt = {
  enable: true,
  package: 'egg-full-jwt',
};
```

## Configuration

```js
// {app_root}/config/config.default.js
exports.fullJwt = {
  secret: 'your key',
  exp: 'expire time', // default 3600 seconds
};
```

see [config/config.default.js](config/config.default.js) for more detail.

## Example

```js
'use strict';

module.exports = app => {
  class HomeController extends app.Controller {
    // /login?userId=10001
    async login() {
      // password check ...

      const { userId } = this.ctx.query;

      const token = await app.fullJwt.sign({ userId });

      // cookies
      this.ctx.cookies.set('token', token, {
        maxAge: 24 * 3600 * 1000 * 1,
        httpOnly: true,
      });

      this.ctx.body = 'login success';
    }

    async index() {
      const token = this.ctx.cookies.get('token');

      if (token === false) {
        this.ctx.redirect('/login');
      }

      const { userId } = await app.fullJwt.verify(token);
      if (userId) {
        this.ctx.redirect('/login');
      }

      this.ctx.body = 'hello World';
    }
  }
  return HomeController;
};
```

## License

[MIT](LICENSE)

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