@medusajs/rbac
Documentation | Website
Building blocks for digital commerce
RBAC (role-based access control) Module for Medusa: manages roles, policies, role-policy assignments, and role assignments. Use it to control which admin users can perform which operations on which resources. It ships with @medusajs/medusa and is registered by adding it to the modules of your medusa-config.ts.
At a glance
| Package | @medusajs/rbac |
| Type | Commerce Module |
| Module key | Modules.RBAC ("rbac") |
| Registered by default | No |
| Import from | @medusajs/medusa/rbac |
Features
- Define policies as a resource and operation pair, such as
product:read. - Group policies into roles, and assign roles to users and other references.
- Seeds a Super Admin role with a wildcard policy that grants full access.
- Powers the
/rbac/*Admin API routes and theauthorizeroute middleware, which are active only while the module is installed.
Installation
No installation needed. The module is included in @medusajs/medusa. Register it in medusa-config.ts.
Usage
Add the module to medusa-config.ts:
import { defineConfig } from "@medusajs/framework/utils"
module.exports = defineConfig({
// ...
modules: [
{
resolve: "@medusajs/medusa/rbac",
},
],
})
Then run migrations with npx medusa db:migrate.