Talon Auth integrates with Hono as typed middleware. Hono runs on Node.js, Bun, Deno, and Cloudflare Workers — the auth middleware works identically across all runtimes.
Install the packages:
npm install hono talon-auth
# For Node.js:
npm install @hono/node-server
Create a verifier with your app ID from the Talon dashboard:
import { createVerifier } from 'talon-auth'
const verifier = createVerifier({ appId: '[your-app-id]' })
Use createMiddleware with a typed Variables map so the verified user is accessible in downstream handlers via c.get('user'). On failure, Hono's built-in error handling returns a 500 — throw an HTTPException to return a 401 instead:
import { createMiddleware } from 'hono/factory'
type Variables = { user: { email: string } }
const authenticate = createMiddleware<{ Variables: Variables }>(async (c, next) => {
const { user } = await verifier.verifyHeader(c.req.header('authorization')!)
c.set('user', user!)
await next()
})
Pass the middleware to any route that requires authentication:
const app = new Hono<{ Variables: Variables }>()
app.get('/message', authenticate, (c) => {
return c.json({ message: `Hello ${c.get('user').email}!` })
})
Replace @hono/node-server with the adapter for your target runtime and keep the rest of the code unchanged:
| Runtime | Adapter |
|---|---|
| Bun | export default app |
| Deno | export default app |
| Cloudflare Workers | export default app |
The example below uses @hono/node-server to run locally. The index route serves an HTML page with the <talon-login> component, and the /message route verifies the JWT via the authenticate middleware.