# @onelastjedi/node-jwt

> Sign and verify JSON Web Tokens in it's simplest form

Latest version **1.0.6** (published 2023-10-31) · AGPL license · 0 weekly downloads

## Install

```sh
npm install @onelastjedi/node-jwt
pnpm add @onelastjedi/node-jwt
yarn add @onelastjedi/node-jwt
bun add @onelastjedi/node-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 | 2023-10-31 |
| First published | 2023-10-14 |
| Weekly downloads | 0 |
| License | AGPL |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 45.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | J.D |
| Maintainers | onelastjedi |
| Keywords | JWT, Node JWT, JSON Web Token, JWT sign, JWT verify, crypto |

## Links

- npm: https://www.npmjs.com/package/@onelastjedi/node-jwt
- Repository: https://github.com/onelastjedi/node-jwt
- Homepage: https://phon.one/node-jwt
- Issues: https://github.com/onelastjedi/node-jwt/issues
- npm.io page: https://npm.io/package/@onelastjedi/node-jwt

## 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) — 2023-10-31
- 1.0.3 — 2023-10-15
- 1.0.2 — 2023-10-14
- 1.0.0 — 2023-10-14

## README

![bundle size](https://img.shields.io/bundlephobia/minzip/@onelastjedi/node-jwt)
![version](https://img.shields.io/npm/v/@onelastjedi/node-jwt)
![downloads](https://img.shields.io/npm/dm/@onelastjedi/node-jwt)

# node-jwt

JavaScript library to sign and verify JSON Web Tokens in it's simplest form.
Has no dependencies.

## Installation

If you use npm, `npm install @onelastjedi/node-jwt`. You can also download the [latest release on GitHub](https://github.com/onelastjedi/node-jwt/releases/latest).

## Use

```js
import jwt from '@onelastjedi/node-jwt'

const secret = process.env.__SECRET__

const data = {
  exp: 60 * 60 * 24 * 7, // 7 days
  user: { id: 1, name: 'Mary' }
}

jwt.sign(data, secret) // eyJhbGc.....
jwt.verify(token, secret)
/*
  {
    alg: 'HS256',
    typ: 'JWT',
    user: { id: 1, name: 'Mary' },
    iat: ...,
    exp: ...,
    }
*/

```

## API

#### `jwt.sign(body, secret, [alg])`

Generated JWT will include an iat (issued at) claim by default. For expiration claim (exp) simply add it to payload. Default signature is `HS256`.

```js
const exp = 60 * 60 * 24 * 365 // 365 days
const token = jwt.sign({ foo: 'bar', exp: exp }, secret, 'HS384')
```

#### `jwt.verify(token, secret)`

The result of this transformation will be a decrypted body. Possible thrown errors during verification.

```js
const data = jwt.verify(token, secret)
```

## Errors

`TokenError`: token is expired or signature is invalid.

## Algorithms supported

| Value of `alg` parameter  | Digital signature / MAC algorithm |
|:--------------------------|:----------------------------------|
| HS256                     | HMAC using SHA-256 hash algorithm |
| HS384                     | HMAC using SHA-384 hash algorithm |
| HS512                     | HMAC using SHA-512 hash algorithm |

### License

[AGPL](LICENSE)

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