@hono-middlewares/permify
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@hono-middlewares/permify

This package provides a middleware for Hono to check permissions against permify endpoints.

Installation

npm i @hono-middlewares/permify

Usage

const app = new Hono();

// Init the permify middleware with the permify client
const { checkPermission } = createCheckPermissionMiddleware({
	client: {
		cert: null,
		endpoint: "localhost:3476",
	},
});

// Set the subject id for permify validation
// If you using the @hono-middlewares/jwks middleware, you can skip this step
// because the middleware will set the subject id automatically
app.use("*", createMiddleware(async (c, next) => {
    c.set("sub", "acct_01j6wwsyzteqqbe76dt28vdfdr");
    await next();
}));

// Define endpoiunt with checkPermission middleware
app.get("/team/:teamId", checkPermission({
		entity: { id: "teamId", type: "team" },
		permission: "view",
	}),
	(c) => {
		c.text("Authorized to view team");
	},
);

Licensed under the MIT License.

Package Sidebar

Install

npm i @hono-middlewares/permify

Weekly Downloads

2

Version

1.1.0

License

MIT

Unpacked Size

17.8 kB

Total Files

7

Last publish

Collaborators

  • kiosk.company