Hono

Install Kilpi for Hono


Install & setup Kilpi

Install Kilpi and setup your Kilpi instance by following the quickstart guide.

export const Kilpi = createKilpi({
getSubject,
policies,
...
})

Provide scope

To use the full feature set of Kilpi, you need to provide a scope for each request. This can be done by using the Kilpi.runInScope method as a middleware.

app.use(async (_, next) => {
await Kilpi.runInScope(async () => {
await next();
})
})

Handle unauthorized errors

Since Hono supports throwing HTTP exceptions, handling errors is straightforward with a middleware.

app.use(async (_, next) => {
Kilpi.onUnauthorized(({ message }) => {
throw new HTTPException(403, { message })
})
await Kilpi.runInScope(async () => {
await next();
})
})