Hono.js middleware for authenticating API keys
Hono - [炎] means flame🔥 in Japanese - is a small, simple, and ultrafast web framework for the Edges. It works on any JavaScript runtime: Cloudflare Workers, Fastly Compute@Edge, Deno, Bun, Vercel, Netlify, Lagon, AWS Lambda, Lambda@Edge, and Node.js.
@unkey/hono
offers a middleware for authenticating API keys with unkey.
bash npm install @unkey/hono
Authorization
header and then verifies it with unkey.
The result of the verification will be written to the context and can be access with c.get("unkey")
.
Authorization
header. You can change this by passing a custom header name to the middleware.
401
error response like this
getKey
function.
HTTPException
like hono recommends
To handle errors globally you can pass an onError
handler to the middleware.
The handler will be called with the context and the error.
401
response if the key is invalid and not continue with the request.
To do this you can pass a handleInvalidKey
handler to the middleware.
See here for the full result
object.