Skip to main content
@talosjs/jwt is a small toolkit for working with JSON Web Tokens. It wraps the JOSE library to sign tokens with the HS256 algorithm, validate them, and read their header and payload. The signing secret is read from the JWT_SECRET environment variable through @talosjs/app-env.

Installation

Add the package to your project with Bun.

Usage

The Jwt class takes an AppEnv instance that exposes JWT_SECRET. Once constructed, you can create tokens, check their validity, and decode them.

Verifying a token

isValid checks both the signature and the standard claims (such as expiration), returning a boolean instead of throwing.

Reading the payload and header

Decoding does not verify the signature, so only call these after isValid on tokens you trust.

Typical uses

You’d reach for this to issue stateless access tokens after a user logs in, then verify the incoming bearer token in middleware before a route runs. Once a token is verified, the same instance reads its claims back out: user id, role, audience, expiry. It isn’t the right fit for opaque session tokens kept in a database, nor when an external identity provider already issues and validates tokens on your behalf.