jwt-decode

A lightweight TypeScript library for decoding JSON Web Token payloads and headers in the browser and Node.js.

Library
npm
v4.0.0
3,395stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
65/100Good
Development Activity52
Maintenance24
Community84
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
70/100Good
Architecture75
Code Quality80
Innovation78
Learning Curve45

jwt-decode is a zero-runtime-dependency library for decoding JSON Web Tokens (JWTs) in browser and Node.js environments. It exposes a single function, jwtDecode, that splits a JWT into its base64url-encoded segments and returns the decoded JSON payload (or header) as a plain object — it does not verify the token’s signature. Maintained by Auth0, it ships dual ESM and CommonJS builds plus a standalone browser script-tag entry point, and is one of the most widely depended-on packages in the JavaScript JWT ecosystem at roughly 18 million weekly downloads.

The library specifically handles the tricky parts of base64url decoding: non-standard padding lengths, UTF-8/unicode payload characters, and malformed input. It throws a typed InvalidTokenError with a descriptive message distinguishing between a non-string token, a missing segment, invalid base64, and invalid JSON, so callers can branch on failure without string-matching generic errors. Because it deliberately does not validate signatures, the README recommends pairing it with a server-side verification library (express-jwt, koa-jwt, or a framework’s built-in JWT bearer middleware) whenever a token’s authenticity must be trusted rather than just its claims read.

What You Get

  • A single jwtDecode() function that returns the parsed JWT payload or header as a typed object.
  • TypeScript types for JwtHeader and JwtPayload, extensible with your own custom claim shapes via generics.
  • A typed InvalidTokenError class with specific messages for missing parts, invalid base64, and invalid JSON.
  • Dual ESM/CommonJS build output plus a browser-ready ES module file for direct <script type="module"> use.

Common Use Cases

  • Reading claims client-side - Decoding an access or ID token in a single-page app to read claims like exp or sub without a server round-trip.
  • Checking token expiry - Comparing the decoded exp/iat timestamps in the browser to decide whether a session token needs refreshing before an API call.
  • Inspecting a JWT header for kid - Passing { header: true } to retrieve the header segment and select the correct signing key elsewhere in a verification flow.
  • Non-browser environments - Combined with an atob polyfill such as core-js/stable/atob, decoding tokens in runtimes (e.g. older React Native) that lack a native atob global.

Under The Hood

Architecture The library is intentionally a single module (lib/index.ts): one exported jwtDecode function, two private helpers (b64DecodeUnicode and base64UrlDecode) for the base64url-to-unicode transform, and an InvalidTokenError class. There is no internal layering, dependency injection, or I/O — jwtDecode is a pure synchronous string-to-object transform, so the entire “architecture” is a single, narrow surface. The build step compiles this one file twice, once each for tsconfig.cjs.json and tsconfig.esm.json, with a prebuild script stamping a package.json into the CJS output directory so Node resolves it as CommonJS. Given the package’s scale (tens of millions of weekly downloads), any change to the jwtDecode signature or error messages would ripple across an enormous number of consumers instantly, so the minimalism looks deliberate rather than accidental.

Tech Stack Written in TypeScript with zero runtime dependencies (it relies only on the global atob), compiled with the native tsc compiler (no bundler like esbuild/tsup), and tested with Jest across both a node and a jsdom test environment to exercise browser and non-browser code paths. Linting uses ESLint 9’s flat config with typescript-eslint, formatting is enforced with Prettier and lint-staged/Husky pre-commit hooks, and package correctness is checked with publint. CI runs a Node 18/20 build matrix on GitHub Actions, with Snyk and Semgrep scanning for dependency and code-level security issues, and releases are automated via a dedicated npm-release workflow keyed off release branches.

Code Quality The single test file exercises the default payload decode, header decoding via { header: true }, UTF-8 and binary payload edge cases, both single- and double-character base64 padding, and every InvalidTokenError branch (non-string input, missing token part, invalid base64, invalid JSON) — solid coverage for a small, focused surface area, though there’s no dedicated test asserting the compiled CJS/ESM build artifacts themselves. TypeScript strict typing is used throughout, errors are raised as a distinguishable typed class rather than generic Error throws, and every PR runs lint, format-check, and both test suites in CI before merge.

API Design The public API is a single function with a sensible default (jwtDecode(token) decodes the payload; { header: true } opts into decoding the header instead), and overloaded TypeScript signatures give strong return-type inference based on that option without requiring a manual type assertion. There’s no setup, configuration object, or class instantiation required — install and call. The main friction points are the reliance on a global atob (requiring a polyfill in environments like older React Native) and the fact that “decode” deliberately does not mean “verify,” which the README calls out prominently since it is a common source of confusion for developers who assume decoding implies the token is trustworthy.

Used by 25 apps in this directory

TypeScript
99%
Other

Activepieces

Automation · AI Assistants

24,298

Open-source AI automation platform that converts 280+ workflow integrations into MCP servers for LLMs, with no-code builders and TypeScript extensibility.

View details
92
Repo Health
85
Technical
64
Dependency
Built with
TypeScript99%
Updated today
TypeScript
53%
MIT

Anarlog

Note Taking · AI Assistants · Productivity

9,252

Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.

View details
86
Repo Health
77
Technical
68
Dependency
Built with
TypeScript53%
Rust35%
Updated today
Python
68%
Other

Baserow

No Code Platforms · Databases

5,830

Open-source no-code platform to build databases, apps, automations, and AI agents — self-hosted or cloud, with full data ownership.

View details
89
Repo Health
84
Technical
68
Dependency
Built with
Python68%
JavaScript16%
Vue12%
Updated yesterday
TypeScript
98%
Apache 2.0

Cline

AI Code Assistants

67,585

An open-source AI coding agent that lives in your editor and terminal — reads and edits your codebase, runs commands, browses the web, and requires human approval for every action by default.

View details
89
Repo Health
74
Technical
65
Dependency
Built with
TypeScript98%
Updated 2 days ago
TypeScript
95%
AGPL 3.0

Docmost

Productivity · Note Taking · Collaboration

21,600

Self-hosted collaborative wiki and knowledge base with real-time editing, diagrams, AI assistance, and enterprise access controls — a modern alternative to Confluence and Notion.

View details
89
Repo Health
70
Technical
70
Dependency
Built with
TypeScript95%
Updated yesterday
TypeScript
62%
Other

Flowise

Developer Tools · Automation · No Code Platforms

55,427

Drag-and-drop visual builder for AI agents, RAG pipelines, and multi-agent systems—deploy anywhere in minutes.

View details
86
Repo Health
77
Technical
63
Dependency
Built with
TypeScript62%
JavaScript27%
Updated 3 weeks ago
TypeScript
99%
AGPL 3.0

fountain-ink

Blogging

64

A self-hostable, decentralized blogging platform built on Lens Protocol — own your content, audience, and distribution forever.

View details
26
Repo Health
66
Technical
66
Dependency
Built with
TypeScript99%
Updated 7 months ago
TypeScript
97%
Other

Infisical

Security · Devops

29,145

The open-source platform for secrets, certificates, privileged access, and AI agent security — all in one self-hostable system.

View details
91
Repo Health
84
Technical
65
Dependency
Built with
TypeScript97%
Updated yesterday
Vue
50%
GPL 3.0

IT-Tools

Developer Tools

40,498

A unified collection of 88 web-based developer utilities — from JSON formatting to subnet calculation — all self-hostable, keyboard-searchable, and offline-ready.

View details
60
Repo Health
74
Technical
63
Dependency
Built with
Vue50%
TypeScript48%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search