Authentication Middleware in Hono

From the Hono cheat sheet · Middleware · verified Jul 2026

Authentication Middleware

Basic Auth, Bearer Auth, and JWT middleware

typescript
import { basicAuth } from 'hono/basic-auth'
import { bearerAuth } from 'hono/bearer-auth'
import { jwt } from 'hono/jwt'

// Basic Auth
app.use('/admin/*', basicAuth({
  username: 'admin',
  password: 'secret123',
}))

// Bearer Token Auth
app.use('/api/*', bearerAuth({
  token: 'my-secret-token',
}))

// JWT Auth
app.use('/auth/*', jwt({
  secret: 'my-jwt-secret',
}))

app.get('/auth/profile', (c) => {
  const payload = c.get('jwtPayload')
  return c.json(payload)
})
💡 basicAuth sends WWW-Authenticate header on failure
⚡ bearerAuth expects "Authorization: Bearer <token>" header
📌 JWT payload accessible via c.get("jwtPayload")
🎯 Use sign() from "hono/jwt" to create tokens

More Hono tasks

Back to the full Hono cheat sheet