@prsm/jwt
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

jwt

A package for encoding, decoding, and verifying JWTs.

Installation

npm install @prsm/jwt

Encoding

import { encode } from "@prsm/jwt";

const payload = {
  iat: Date.now(),
  exp: Date.now() + 3600,
};

const token = encode(payload, process.env.PRIVATE_KEY);

Verifying

import { verify } from "@prsm/jwt";

const result = verify(token, process.env.PRIVATE_KEY);

if (!result.sig) throw new Error("signature verification failed");
if (result.exp) throw new Error("token has expired");
if (!result.nbf) throw new Error("token is not yet valid")

// token payload is available at result.decoded.payload

Decoding

import { decode } from "@prsm/jwt";

const result = decode(token);
// { header: { alg: "HS256", typ: "JWT" }, payload: { iat: 123456789, exp: 123456789 }, signature: "..."

Readme

Keywords

none

Package Sidebar

Install

npm i @prsm/jwt

Weekly Downloads

1

Version

1.0.8

License

ISC

Unpacked Size

15 kB

Total Files

7

Last publish

Collaborators

  • nvmsy