fastify-permit-io
v1.0.25
Published
Fastify plugin for Permit.io integration
Maintainers
Readme
fastify-permit-io
A Fastify plugin for seamless integration with Permit.io, enabling robust, flexible, and scalable permissions and authorization in your Fastify applications.
Features
- Installs a
Permitinstance on your Fastify server - Supports all Permit.io authorization models (RBAC, ABAC, ReBAC)
- Simple, type-safe integration
Installation
npm install fastify-permit-io permitioUsage
import Fastify from "fastify";
import FastifyPermitio from "fastify-permit-io";
const app = Fastify();
app.register(FastifyPermitio, {
pdp: "https://cloudpdp.api.permit.io",
token: "YOUR_PERMIT_API_KEY",
// ...other Permit config options
});
app.get("/resource", async (request, reply) => {
// Access the Permit instance
const permit = app.permit;
const allowed = await permit.check("user:123", "read", "document:456");
if (!allowed) {
return reply.code(403).send({ error: "Forbidden" });
}
return { data: "Secret document" };
});
app.listen({ port: 3000 });Additional Context
I am not affiliated with permit.io and this project is an independent integration created for convenience. For official support or documentation, please refer to the Permit.io website and their official documentation.
License
Licensed under MIT.
