Skip to content

Use cases ​

The other pages explain one feature at a time. These pages go the other way: they start from a kind of app and show the whole setup for it. Each one covers the roles, the seed, how users get their roles, the route guards in one framework, the edge cases of that app, and a test.

Pick the one closest to your app. Most real apps are a mix, for example a SaaS with a public API.

AppFeaturesIntegrationPage
Blog / CMS with writers, editors, moderators and adminsOwnership checks ("edit own post"), '*' in the seed, before hook for banned users, typed namesExpress, Vue v-canBlog / CMS
B2B SaaS where a user has a different role in each organizationTeams, invites, switching organization, stacked roles, typed namesNext.js, React <Can>B2B SaaS
E-commerce back office for warehouse, cashier, support and managerWildcard permissions (orders.*), refund limits, typed names with wildcardsNestJS, Vue v-canE-commerce back office
Public REST API where API keys get scopesMultiple guards (web and api), direct permissions, preset roles, exposeRequirementsHonoPublic API
Company admin panel with read-only support and temporary accessSuper-admin (superAdminRoles), before hook, direct permissions that expire, eventsFastify, React <Can>Internal admin panel

Every page has the same sections:

  1. The app: what it does and who uses it.
  2. Roles and permissions: a table of roles and permissions, and why it is split that way.
  3. Seed it: the definition for rbac.sync(), with typed names.
  4. Assign roles: sign-up, invites, promotion, and so on.
  5. Guard the routes: server guards, plus the UI where the app has one.
  6. Edge cases: the things that are specific to this kind of app.
  7. Test it: a Vitest test with the in-memory adapter.

Start from the principles

All five pages follow the same rule: check permissions in code, hand them out with roles. If you haven't read it yet, Roles vs permissions explains why.

For a single feature in more depth, see the recipes and the Basic usage pages.

Released under the MIT License. Inspired by spatie/laravel-permission.