/Knowledge/sources/honojs__hono/llms-full/jwt-auth-middleware-usage--62dcdd9ddd39.md
JWT Auth Middleware: Usage - hono-docs
JWT Auth Middleware: Usage Source evidence: /Sources/honojs hono/provenance.md Canonical citation: https://hono.dev/llms full.txt usage Summary ts // Specify...
JWT Auth Middleware: Usage
Source evidence: /Sources/honojs__hono/provenance.md Canonical citation: https://hono.dev/llms-full.txt#usage
Summary
```ts // Specify the variable types to infer the c.get('jwtPayload'): type Variables = JwtVariables const app = new Hono () app.use( '/auth/*', jwt({ secret: 'it-is-very-secret', alg: 'HS256', }) ) app.get('/auth/page', (c) => { return...
Content
// Specify the variable types to infer the `c.get('jwtPayload')`:
type Variables = JwtVariables
const app = new Hono<{ Variables: Variables }>()
app.use(
'/auth/*',
jwt({
secret: 'it-is-very-secret',
alg: 'HS256',
})
)
app.get('/auth/page', (c) => {
return c.text('You are authorized')
})
Get payload:
const app = new Hono()
app.use(
'/auth/*',
jwt({
secret: 'it-is-very-secret',
alg: 'HS256',
verification: {
iss: 'my-trusted-issuer',
aud: 'my-api',
},
})
)
app.get('/auth/page', (c) => {
const payload = c.get('jwtPayload')
return c.json(payload) // eg: { "sub": "1234567890", "name": "John Doe", "iat": 1516239022, "iss": "my-trusted-issuer" }
})
::: tip
jwt() is just a middleware function. If you want to use an environment variable (eg: c.env.JWT_SECRET), you can use it as follows:
Metadata
{
"chunk_index": 0,
"citation": "https://hono.dev/llms-full.txt#usage",
"coverage_role": "overview",
"qualified_title": "Hono / llms-full / JWT Auth Middleware > Usage (1)",
"retrieved_at": "2026-07-02T05:51:01Z",
"section_index": 156,
"source_id": "/honojs/hono",
"source_type": "llms_full",
"target_label": "llms-full",
"title": "JWT Auth Middleware: Usage",
"upstream_url": "https://hono.dev/llms-full.txt",
"version": "2026"
}