Hono

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.

Setup

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]' })

Auth middleware

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}!` })
})

Other runtimes

Replace @hono/node-server with the adapter for your target runtime and keep the rest of the code unchanged:

RuntimeAdapter
Bunexport default app
Denoexport default app
Cloudflare Workersexport default app

Example

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.

hono.ts
Subscribe to our NewsletterGet new Feathers content as it becomes available.
Talon Auth logo

Copyright © 2012 - 2026 feathers.dev