Skip to content

Fastify

← Documentation home

Use fastifyGuard() as a preHandler to call sync evaluate() before your route handler. Same getter options as Express — see Middleware reference.

typescript
import { fastifyGuard } from "@siremzam/sentinel/middleware/fastify";

fastify.post("/invoices/:id/approve", {
  preHandler: fastifyGuard(engine, "invoice:approve", "invoice", {
    getSubject: (req) => req.user,
    getResourceContext: (req) => ({ id: req.params.id }),
    getTenantId: (req) => req.headers["x-tenant-id"] as string,
  }),
}, handler);

For async conditions, evaluate in the handler with evaluateAsync() — see Async conditions.


Released under the MIT License.