Skip to content

Samox/jwt-parse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JWT Parser

Installation

npm install @samox/jwt-parse

or

yarn add @samox/jwt-parse

IMPORTANT: This library doesn't validate the token, any well formed JWT can be decoded. You should validate the token in your server-side logic by using something like express-jwt, koa-jwt, Owin Bearer JWT, etc.

Usage

import { parseJWT } from "@samox/jwt-parse";

const JWT =
  "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";

type JWTPayload = { sub: string; name: string; iat: number };
type JWTHeader = { alg: string; typ: string };

const { payload, header } = parseJWT<JWTPayload, JWTHeader>(JWT);

console.log("Payload", payload.name);
console.log("Header", header);

About

Helper lib to type-safely extract JWT payload or header

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors