The name to use for JWT functionality in the Elysia context (defaults to 'jwt')
Configuration options for the JWT plugin
An Elysia plugin that adds JWT functionality to the application context
Basic usage
const app = new Elysia()
.use(jwt({
secret: process.env.JWT_SECRET!,
exp: '1h'
}))
.post('/login', ({ jwt }) => {
return jwt.sign({ userId: 123, role: 'user' });
})
.get('/protected', async ({ jwt, headers }) => {
const token = headers.authorization?.replace('Bearer ', '');
const payload = await jwt.verify(token);
if (!payload) throw new Error('Invalid token');
return { user: payload };
});
The
elysiaJwtPlugin
provides secure JSON Web Token (JWT) authentication capabilities for Elysia applications.This plugin leverages the industry-standard
jose
library to ensure robust JWT handling with modern cryptographic standards.