TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/elysiajs/documentation/llms.txt
Use this file to discover all available pages before exploring further.
@elysia/jwt plugin adds JWT support to Elysia handlers. It injects a jwt object into the handler context that exposes sign and verify methods, built on top of jose.
Installation
Basic usage
- Header-based
Handler values
The plugin adds ajwt object to the handler context under the name specified in the name config option.
jwt.sign(payload)
Signs a JWT payload and returns a token string.
jwt.verify(token)
Verifies a token against the configured secret. Returns the decoded payload on success, or false if verification fails.
Configuration
The plugin extends config options from jose.name
The property name under which the jwt object is injected into the handler context. Use different names to register multiple JWT instances with different secrets or algorithms in the same app:
secret
The private key used to sign and verify JWT payloads.
schema
A TypeBox schema for strict type validation of the JWT payload.
alg
Default: 'HS256'
The signing algorithm. Supported values from jose:
HS256 HS384 HS512 PS256 PS384 PS512 RS256 RS384 RS512 ES256 ES256K ES384 ES512 EdDSA
exp
The expiration time for signed tokens. Accepts a time string such as '7d', '2h', or '30m'.
Setting an expiration date
Standard JWT claims
All standard RFC7519 claims are supported as config options and as payload fields:| Claim | Description |
|---|---|
iss | Issuer — identifies who issued the JWT |
sub | Subject — identifies the principal of the JWT |
aud | Audience — recipients the JWT is intended for |
exp | Expiration time |
nbf | Not before — earliest time to accept the token |
iat | Issued at |
jti | JWT ID — unique identifier for the token |