npm.io
2.22.7 • Published 4d ago

@medusajs/rbac

Licence
SEE LICENSE IN LICENSE
Version
2.22.7
Deps
0
Size
92 kB
Vulns
0
Weekly
0
Stars
36.7K

Medusa logo

@medusajs/rbac

Documentation | Website

Building blocks for digital commerce

Medusa is released under the MIT license. PRs welcome! Discord Chat Follow @medusajs

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 the authorize route 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.

Resources