Skip to content

Latest commit

 

History

History

README.md

RBAC Examples

This directory contains self-contained TypeScript snippets that showcase how to use the library in different scenarios. Each file can be executed with ts-node (or transpiled to JavaScript) and is fully documented in English.

Core building blocks

  • configuredRBAC.ts creates a reusable RBAC factory configured with logging disabled.
  • roles.ts defines a role hierarchy with conditional permissions using the when callback for additional context checks.
  • index.ts demonstrates how to instantiate RBAC with the predefined roles and perform permission checks for multiple roles.
  • basicUsage.ts shows a real-world check where user data is passed as context to evaluate permissions.

Updating roles at runtime

  • updateRoles.ts illustrates how to add new roles and merge updates without restarting your application.

Database adapters

Multi-tenant environments

  • multiTenant.ts stores and retrieves tenant-scoped roles using the MongoDB adapter and createTenantRBAC helper.

Framework middlewares

Each example is intentionally concise and focuses on a single scenario so you can copy the file that best matches your use case and adapt it to your project.