@clowk/hono
Hono middleware for Clowk authentication
Install
npm install @clowk/hono @clowk/coreOverview
Hono middleware that verifies JWTs and sets the authenticated user on the context. Works on every runtime Hono supports: Cloudflare Workers, Bun, Deno, and Node.js.
What it provides:
clowkAuth()— middleware factoryc.get('clowkUser')— the decoded user after verification
clowkAuth
import { clowkAuth } from '@clowk/hono'
app.use('*', clowkAuth())Options
| Option | Type | Default | Description |
|---|---|---|---|
onError | (err, c) => Response | Returns 401 JSON | Custom error handler |
extractToken | (c) => string | null | Auto-detect | Custom token extractor |
Token extraction order
The middleware looks for the JWT in this order:
- Query parameter:
?token=eyJ... - Cookie:
clowk_token - Authorization header:
Bearer eyJ...
Context variables
After successful verification:
app.get('/me', (c) => {
const user = c.get('clowkUser')
// => { id, email, name, provider, iat, exp }
return c.json({ user })
})User type
interface ClowkUser {
id: string
email: string
name: string
provider: string
iat: number
exp: number
}Error handling
By default, invalid or missing tokens return:
{ "error": "Unauthorized" }Customize with onError:
const auth = clowkAuth({
onError: (err, c) => {
return c.json({ error: err.message }, 401)
},
})Runtimes
| Runtime | Deploy target |
|---|---|
| Cloudflare Workers | wrangler deploy |
| Bun | bun run src/index.ts |
| Deno | deno run src/index.ts |
| Node.js | node src/index.ts |
The @clowk/core package uses native fetch and Web Crypto APIs — no Node.js-specific dependencies.
Next steps
- Hono quickstart — getting started guide
- @clowk/core reference — foundation package