Skip to content

docs: add NestJS integration example - #551

Closed
Muzzu8421 wants to merge 1 commit into
apache:masterfrom
Muzzu8421:add-nestjs-docs
Closed

docs: add NestJS integration example#551
Muzzu8421 wants to merge 1 commit into
apache:masterfrom
Muzzu8421:add-nestjs-docs

Conversation

@Muzzu8421

Copy link
Copy Markdown

This PR adds a NestJS integration example for Casbin using a custom guard.

It demonstrates how to use Casbin for authorization in a NestJS application, including installation, guard implementation, and policy configuration.

The example shows how to protect routes using a NestJS guard and enforce access control with Casbin.

This will help developers easily integrate Casbin with modern Node.js frameworks like NestJS.

@hsluoyz

hsluoyz commented Aug 6, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution! A couple of things though: node-casbin doesn't host usage guides — all docs live in the casbin-website repo (casbin.apache.org/docs), so a docs/ file here wouldn't be linked or discoverable. We also already have an official NestJS integration, nest-authz (https://github.com/apache/casbin-nest-authz) with a full example repo, so a guide should build on that rather than a hand-rolled guard. The example itself also has a few issues worth fixing first: the subject is hardcoded to 'alice' instead of read from request.user, request.url includes the query string so /data?page=1 won't match the /data policy (RESTful paths need keyMatch2), the enforcer is created in an async onModuleInit without implements OnModuleInit (racy — better to provide the Enforcer as a useFactory provider and inject it), and every code block is tagged ```bash even for TS/conf/csv. I'd suggest closing this and opening a PR against casbin-website instead. Thanks again!

@hsluoyz hsluoyz closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants