Scenarios

Admin Panel with Modules and Tabs

Real-world guide to building a multi-module admin panel with role-based access

The Situation

You're building an admin panel with modules (Orders, Products, Customers, Reports, Settings). Each module has tabs and sub-tabs. For example:

  • Orders module has Refunds, Returns, and Shipping tabs
  • Refunds tab has View and Approve sub-tabs
  • A support agent can view refunds but not approve them
  • A finance manager can approve refunds and export reports

You need to show the right menu items to each user and protect every action.

Permission Design

Name permissions module.tab.subtab.action to scale cleanly:

Module Tabs Sub-tabs Permissions
Orders Refunds View, Approve orders.refunds.view, orders.refunds.approve
Returns View, Process orders.returns.view, orders.returns.process
Shipping View, Edit orders.shipping.view, orders.shipping.edit
Products Catalog View, Edit products.catalog.view, products.catalog.edit
Pricing View, Update products.pricing.view, products.pricing.update
Customers List View, Edit customers.list.view, customers.list.edit
Segments Create, Delete customers.segments.create, customers.segments.delete
Reports Sales View, Export reports.sales.view, reports.sales.export
Analytics View reports.analytics.view
Settings Team Manage settings.team.manage
Audit View settings.audit.view

Roles grant access at any level:

Role Permissions
Support orders.refunds.view, orders.returns.view, orders.shipping.view, customers.list.view
Manager orders.* (all order permissions), customers.list.*, reports.sales.view
Finance orders.refunds.approve, products.pricing.update, reports.sales.export, reports.analytics.view
Admin * (all permissions)

Setup Code

Define your permissions and roles:

import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

export const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: [
    // Orders
    "orders.refunds.view", "orders.refunds.approve",
    "orders.returns.view", "orders.returns.process",
    "orders.shipping.view", "orders.shipping.edit",
    // Products
    "products.catalog.view", "products.catalog.edit",
    "products.pricing.view", "products.pricing.update",
    // Customers
    "customers.list.view", "customers.list.edit",
    "customers.segments.create", "customers.segments.delete",
    // Reports
    "reports.sales.view", "reports.sales.export",
    "reports.analytics.view",
    // Settings
    "settings.team.manage",
    "settings.audit.view"
  ],
  roles: ["admin", "manager", "finance", "support"],
  strict: true
});

export async function setupAdminPanel() {
  const { createdRoles } = await perms.sync();
  
  // Assign permissions to roles
  if (createdRoles.includes("admin")) {
    await perms.role("admin").givePermission("*");
  }
  
  if (createdRoles.includes("manager")) {
    await perms.role("manager").givePermission(
      "orders.refunds.view", "orders.refunds.approve",
      "orders.returns.view", "orders.returns.process",
      "orders.shipping.view", "orders.shipping.edit",
      "customers.list.view", "customers.list.edit",
      "reports.sales.view"
    );
  }
  
  if (createdRoles.includes("finance")) {
    await perms.role("finance").givePermission(
      "orders.refunds.approve",
      "products.pricing.update",
      "reports.sales.export",
      "reports.analytics.view"
    );
  }
  
  if (createdRoles.includes("support")) {
    await perms.role("support").givePermission(
      "orders.refunds.view",
      "orders.returns.view",
      "orders.shipping.view",
      "customers.list.view"
    );
  }
}
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

export const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: [
    // Orders
    "orders.refunds.view", "orders.refunds.approve",
    "orders.returns.view", "orders.returns.process",
    "orders.shipping.view", "orders.shipping.edit",
    // Products
    "products.catalog.view", "products.catalog.edit",
    "products.pricing.view", "products.pricing.update",
    // Customers
    "customers.list.view", "customers.list.edit",
    "customers.segments.create", "customers.segments.delete",
    // Reports
    "reports.sales.view", "reports.sales.export",
    "reports.analytics.view",
    // Settings
    "settings.team.manage",
    "settings.audit.view"
  ],
  roles: ["admin", "manager", "finance", "support"],
  strict: true
});

export async function setupAdminPanel() {
  const { createdRoles } = await perms.sync();
  
  // Assign permissions to roles
  if (createdRoles.includes("admin")) {
    await perms.role("admin").givePermission("*");
  }
  
  if (createdRoles.includes("manager")) {
    await perms.role("manager").givePermission(
      "orders.refunds.view", "orders.refunds.approve",
      "orders.returns.view", "orders.returns.process",
      "orders.shipping.view", "orders.shipping.edit",
      "customers.list.view", "customers.list.edit",
      "reports.sales.view"
    );
  }
  
  if (createdRoles.includes("finance")) {
    await perms.role("finance").givePermission(
      "orders.refunds.approve",
      "products.pricing.update",
      "reports.sales.export",
      "reports.analytics.view"
    );
  }
  
  if (createdRoles.includes("support")) {
    await perms.role("support").givePermission(
      "orders.refunds.view",
      "orders.returns.view",
      "orders.shipping.view",
      "customers.list.view"
    );
  }
}

Backend Protection

Protect whole route groups and individual routes:

Express Middleware

import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";
import { Router } from "express";
import { permlyExpress } from "permly/express";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: [
    "orders.refunds.view", "orders.refunds.approve",
    "orders.returns.view", "orders.returns.process",
    "orders.shipping.view", "orders.shipping.edit",
    "products.catalog.view", "products.catalog.edit",
    "products.pricing.view", "products.pricing.update"
  ],
  roles: ["admin"],
  strict: false
});

await perms.sync();

const guard = permlyExpress(perms, {
  getUserId: (req) => req.user.id,
  onDenied: (req, res, missing) => res.status(403).json({ error: "Forbidden", missing })
});

const router = Router();

// Protect entire Orders group
router.use("/orders", guard.anyPermission(["orders.refunds.*", "orders.returns.*", "orders.shipping.*"]));

// Protect specific routes
router.get("/orders/refunds", guard.permission("orders.refunds.view"), (req, res) => {
  // List refunds
});

router.post("/orders/refunds/:id/approve", guard.permission("orders.refunds.approve"), (req, res) => {
  // Approve refund
});

// Products routes
router.use("/products", guard.anyPermission(["products.*"]));

router.get("/products/pricing", guard.permission("products.pricing.view"), (req, res) => {
  // Show pricing
});

router.patch("/products/pricing/:id", guard.permission("products.pricing.update"), (req, res) => {
  // Update pricing
});
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";
import { Router, type Request, type Response } from "express";
import { permlyExpress } from "permly/express";

interface AuthRequest extends Request {
  user?: { id: number };
}

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: [
    "orders.refunds.view", "orders.refunds.approve",
    "orders.returns.view", "orders.returns.process",
    "orders.shipping.view", "orders.shipping.edit",
    "products.catalog.view", "products.catalog.edit",
    "products.pricing.view", "products.pricing.update"
  ],
  roles: ["admin"],
  strict: false
});

await perms.sync();

const guard = permlyExpress(perms, {
  getUserId: (req: AuthRequest) => req.user?.id || 0,
  onDenied: (req: AuthRequest, res: Response, missing) => res.status(403).json({ error: "Forbidden", missing })
});

const router = Router();

// Protect entire Orders group
router.use("/orders", guard.anyPermission(["orders.refunds.*", "orders.returns.*", "orders.shipping.*"] as any));

// Protect specific routes
router.get("/orders/refunds", guard.permission("orders.refunds.view"), (req: Request, res: Response) => {
  // List refunds
});

router.post("/orders/refunds/:id/approve", guard.permission("orders.refunds.approve"), (req: Request, res: Response) => {
  // Approve refund
});

// Products routes
router.use("/products", guard.anyPermission(["products.*"] as any));

router.get("/products/pricing", guard.permission("products.pricing.view"), (req: Request, res: Response) => {
  // Show pricing
});

router.patch("/products/pricing/:id", guard.permission("products.pricing.update"), (req: Request, res: Response) => {
  // Update pricing
});

Frontend: Show the Right Menu

After login, fetch permissions and filter your menu config:

import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

const menuConfig = [
  {
    id: "orders",
    label: "Orders",
    access: "orders.*",
    tabs: [
      {
        id: "refunds",
        label: "Refunds",
        access: "orders.refunds.*",
        actions: [
          { id: "view", label: "View", access: "orders.refunds.view" },
          { id: "approve", label: "Approve", access: "orders.refunds.approve" }
        ]
      }
    ]
  },
  {
    id: "reports",
    label: "Reports",
    access: "reports.*",
    tabs: [
      {
        id: "sales",
        label: "Sales",
        access: "reports.sales.*",
        actions: [
          { id: "view", label: "View", access: "reports.sales.view" },
          { id: "export", label: "Export", access: "reports.sales.export" }
        ]
      }
    ]
  }
];

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: [
    "orders.refunds.view", "orders.refunds.approve",
    "orders.returns.view", "orders.returns.process",
    "orders.shipping.view", "orders.shipping.edit",
    "reports.sales.view", "reports.sales.export",
    "reports.analytics.view"
  ],
  roles: ["manager"],
  strict: true
});

await perms.sync();
await perms.role("manager").givePermission(
  "orders.refunds.view", "orders.refunds.approve",
  "orders.returns.view", "orders.returns.process",
  "orders.shipping.view", "orders.shipping.edit",
  "reports.sales.view"
);

async function filterMenu(userPermissions) {
  return menuConfig.filter(module => {
    const hasModuleAccess = userPermissions.some(p =>
      p === "*" || p === module.access || p.startsWith(module.id + ".")
    );

    if (!hasModuleAccess) return false;

    if (module.tabs) {
      module.tabs = module.tabs.filter(tab => {
        const hasTabAccess = userPermissions.some(p =>
          p === "*" || p.startsWith(tab.id + ".") || p.startsWith(module.id + "." + tab.id)
        );

        if (!hasTabAccess) return false;

        if (tab.actions) {
          tab.actions = tab.actions.filter(action =>
            userPermissions.includes("*") ||
            userPermissions.includes(module.id + "." + tab.id + "." + action.id)
          );
        }

        return (tab.actions && tab.actions.length > 0) || !tab.actions;
      });
    }

    return (module.tabs && module.tabs.length > 0) || !module.tabs;
  });
}

const userId = 1;
await perms.user(userId).assignRole("manager");
const permissions = await perms.user(userId).getPermissions();
const menu = await filterMenu(permissions);
menu.length > 0; // true
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

interface MenuItem {
  id: string;
  label: string;
  access: string;
  tabs?: Tab[];
}

interface Tab {
  id: string;
  label: string;
  access: string;
  actions?: Action[];
}

interface Action {
  id: string;
  label: string;
  access: string;
}

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: [
    "orders.refunds.view", "orders.refunds.approve",
    "orders.returns.view", "orders.returns.process",
    "orders.shipping.view", "orders.shipping.edit",
    "reports.sales.view", "reports.sales.export",
    "reports.analytics.view"
  ],
  roles: ["manager"],
  strict: true
});

await perms.sync();
await perms.role("manager").givePermission(
  "orders.refunds.view", "orders.refunds.approve",
  "orders.returns.view", "orders.returns.process",
  "orders.shipping.view", "orders.shipping.edit",
  "reports.sales.view"
);

const menuConfig: MenuItem[] = [
  {
    id: "orders",
    label: "Orders",
    access: "orders.*",
    tabs: [
      {
        id: "refunds",
        label: "Refunds",
        access: "orders.refunds.*",
        actions: [
          { id: "view", label: "View", access: "orders.refunds.view" },
          { id: "approve", label: "Approve", access: "orders.refunds.approve" }
        ]
      }
    ]
  },
  {
    id: "reports",
    label: "Reports",
    access: "reports.*",
    tabs: [
      {
        id: "sales",
        label: "Sales",
        access: "reports.sales.*",
        actions: [
          { id: "view", label: "View", access: "reports.sales.view" },
          { id: "export", label: "Export", access: "reports.sales.export" }
        ]
      }
    ]
  }
];

// Filter menu based on user permissions
async function filterMenu(userPermissions: string[]): Promise<MenuItem[]> {
  return menuConfig.filter(module => {
    const hasModuleAccess = userPermissions.some(p =>
      p === "*" || p === module.access || p.startsWith(module.id + ".")
    );

    if (!hasModuleAccess) return false;

    if (module.tabs) {
      module.tabs = module.tabs.filter(tab => {
        const hasTabAccess = userPermissions.some(p =>
          p === "*" || p.startsWith(tab.id + ".") || p.startsWith(module.id + "." + tab.id)
        );

        if (!hasTabAccess) return false;

        if (tab.actions) {
          tab.actions = tab.actions.filter(action =>
            userPermissions.includes("*") ||
            userPermissions.includes(module.id + "." + tab.id + "." + action.id)
          );
        }

        return (tab.actions && tab.actions.length > 0) || !tab.actions;
      });
    }

    return (module.tabs && module.tabs.length > 0) || !module.tabs;
  });
}

// Get user permissions and filter menu
const userId = 1;
await perms.user(userId).assignRole("manager");
const permissions = await perms.user(userId).getPermissions();
const menu = await filterMenu(permissions);
menu.length > 0; // true

Important: Hiding menu items is for convenience only. Always check permissions on the backend before executing actions.

Giving Extra Access

A support agent needs to approve one specific refund temporarily. Don't create a role—give them the permission directly:

import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["orders.refunds.view", "orders.refunds.approve"],
  roles: ["support", "manager"],
  strict: false
});

const { createdRoles } = await perms.sync();
if (createdRoles.includes("manager")) {
  await perms.role("manager").givePermission("orders.refunds.approve");
}

const agentId = 42;

// Grant temporary access
await perms.user(agentId).givePermission("orders.refunds.approve");
const canApprove = await perms.user(agentId).can("orders.refunds.approve");
canApprove; // true

// Later, remove it
await perms.user(agentId).revokePermission("orders.refunds.approve");
const canApproveAfter = await perms.user(agentId).can("orders.refunds.approve");
canApproveAfter; // false
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["orders.refunds.view", "orders.refunds.approve"],
  roles: ["support", "manager"],
  strict: false
});

const { createdRoles } = await perms.sync();
if (createdRoles.includes("manager")) {
  await perms.role("manager").givePermission("orders.refunds.approve");
}

const agentId = 42;

// Grant temporary access
await perms.user(agentId).givePermission("orders.refunds.approve");
const canApprove = await perms.user(agentId).can("orders.refunds.approve");
canApprove; // true

// Later, remove it
await perms.user(agentId).revokePermission("orders.refunds.approve");
const canApproveAfter = await perms.user(agentId).can("orders.refunds.approve");
canApproveAfter; // false

Module Access Permission

Some panels (like Settings) should have a gate permission. Users with settings.audit.view can see audit logs, but only if they also have settings.access:

import express from "express";
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";
import { permlyExpress } from "permly/express";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["settings.access", "settings.audit.view"],
  roles: ["admin"],
  strict: false
});

await perms.sync();
await perms.role("admin").givePermission("settings.access", "settings.audit.view");

const guard = permlyExpress(perms, {
  getUserId: (req) => Number(req.get("x-user-id"))
});

const router = express.Router();

// Protect settings routes with settings.access gate
router.use("/settings", guard.permission("settings.access"));
router.get("/settings/audit", guard.permission("settings.audit.view"), (_req, res) => {
  res.json({ auditLogs: [] });
});
import express, { type Request, type Response } from "express";
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";
import { permlyExpress } from "permly/express";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["settings.access", "settings.audit.view"],
  roles: ["admin"],
  strict: false
});

await perms.sync();
await perms.role("admin").givePermission("settings.access", "settings.audit.view");

const guard = permlyExpress(perms, {
  getUserId: (req: Request) => Number(req.get("x-user-id"))
});

const router = express.Router();

// Protect settings routes with settings.access gate
router.use("/settings", guard.permission("settings.access"));
router.get("/settings/audit", guard.permission("settings.audit.view"), (_req: Request, res: Response) => {
  res.json({ auditLogs: [] });
});

Creating Roles at Runtime

An admin creates a new "Analyst" role and chooses which reports it can view:

import express from "express";
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";
import { permlyExpress } from "permly/express";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: [
    "reports.sales.view", "reports.sales.export",
    "reports.analytics.view"
  ],
  roles: ["analyst"],
  strict: false
});

await perms.sync();
await perms.role("analyst").givePermission("reports.sales.view", "reports.analytics.view");

const guard = permlyExpress(perms, {
  getUserId: (req) => Number(req.get("x-user-id"))
});

const app = express();
app.use(express.json());

// Backend endpoint to assign permissions to roles
app.post("/api/roles", async (req, res) => {
  const { name, permissions } = req.body;

  // Grant permissions to the role  
  const role = perms.role(name);
  for (const perm of permissions) {
    await role.givePermission(perm);
  }

  res.json({ success: true });
});

const server = app.listen(0);

// Frontend: send which permissions to grant
const port = server.address().port;
const response = await fetch("http://localhost:" + port + "/api/roles", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    name: "analyst",
    permissions: ["reports.sales.view", "reports.analytics.view"]
  })
});
const result = await response.json();
result.success; // true
server.close();
import express, { type Request, type Response } from "express";
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";
import { permlyExpress } from "permly/express";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: [
    "reports.sales.view", "reports.sales.export",
    "reports.analytics.view"
  ],
  roles: ["analyst"],
  strict: false
});

await perms.sync();
await perms.role("analyst").givePermission("reports.sales.view", "reports.analytics.view");

const guard = permlyExpress(perms, {
  getUserId: (req: Request) => Number(req.get("x-user-id"))
});

const app = express();
app.use(express.json());

// Backend endpoint to assign permissions to roles
app.post("/api/roles", async (req: Request, res: Response) => {
  const { name, permissions } = req.body as { name: string; permissions: string[] };

  // Grant permissions to the role  
  const role = perms.role(name as any);
  for (const perm of permissions) {
    await role.givePermission(perm as any);
  }

  res.json({ success: true });
});

const server = app.listen(0);

// Frontend: send which permissions to grant
const port = (server.address() as any)?.port;
const response = await fetch("http://localhost:" + port + "/api/roles", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    name: "analyst",
    permissions: ["reports.sales.view", "reports.analytics.view"]
  })
});
const result = await response.json();
result.success; // true
server.close();

Note: TypeScript wildcard autocomplete works 5 levels deep (e.g., orders.refunds.view.action). Deeper paths still work at runtime but won't autocomplete.

Common Mistakes

1. Forgetting Module Access Permission

Wrong:

import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["admin.view", "admin.users"],
  roles: ["admin"],
  strict: false
});

await perms.sync();
const agentId = 42;

// User can view users but didn't check module access
await perms.user(agentId).givePermission("admin.users");
const hasView = await perms.user(agentId).can("admin.users");
const hasAccess = await perms.user(agentId).can("admin.view");
hasView; // true (but missing admin.view!)
hasAccess; // false
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["admin.view", "admin.users"],
  roles: ["admin"],
  strict: false
});

await perms.sync();
const agentId = 42;

// User can view users but didn't check module access
await perms.user(agentId).givePermission("admin.users");
const hasView = await perms.user(agentId).can("admin.users");
const hasAccess = await perms.user(agentId).can("admin.view");
hasView; // true (but missing admin.view!)
hasAccess; // false

Right:

import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["admin.view", "admin.users"],
  roles: ["admin"],
  strict: false
});

await perms.sync();
const agentId = 42;

// Always grant the module access permission first
await perms.user(agentId).givePermission("admin.view");
await perms.user(agentId).givePermission("admin.users");

const hasAccess = await perms.user(agentId).can("admin.view");
const hasView = await perms.user(agentId).can("admin.users");
hasAccess; // true
hasView; // true
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["admin.view", "admin.users"],
  roles: ["admin"],
  strict: false
});

await perms.sync();
const agentId = 42;

// Always grant the module access permission first
await perms.user(agentId).givePermission("admin.view");
await perms.user(agentId).givePermission("admin.users");

const hasAccess = await perms.user(agentId).can("admin.view");
const hasView = await perms.user(agentId).can("admin.users");
hasAccess; // true
hasView; // true

2. Hiding in UI but Not Protecting Backend

Wrong:

// Frontend hides the "Approve" button
const permissions = ["admin.settings"];
if (!permissions.includes("admin.users")) {
  // Don't show button
}

// But endpoint is unprotected! (This is just illustration)
// router.post("/api/users/:id/ban", handler);
// A user could manually POST to this unprotected endpoint!
// Frontend hides the "Approve" button
const permissions = ["admin.settings"];
if (!permissions.includes("admin.users")) {
  // Don't show button
}

// But endpoint is unprotected! (This is just illustration)
// router.post("/api/users/:id/ban", handler);
// A user could manually POST to this unprotected endpoint!

Right:

import express from "express";
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";
import { permlyExpress } from "permly/express";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["admin.settings", "admin.users"],
  roles: ["admin"],
  strict: false
});

await perms.sync();

const guard = permlyExpress(perms, {
  getUserId: (req) => Number(req.get("x-user-id"))
});

const router = express.Router();

// Always protect on backend—never rely on frontend hiding
router.post("/api/users/:id/ban",
  guard.permission("admin.users"),
  (_req, res) => {
    res.json({ banned: true });
  }
);
import express, { type Request, type Response } from "express";
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";
import { permlyExpress } from "permly/express";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["admin.settings", "admin.users"],
  roles: ["admin"],
  strict: false
});

await perms.sync();

const guard = permlyExpress(perms, {
  getUserId: (req: Request) => Number(req.get("x-user-id"))
});

const router = express.Router();

// Always protect on backend—never rely on frontend hiding
router.post("/api/users/:id/ban",
  guard.permission("admin.users"),
  (_req: Request, res: Response) => {
    res.json({ banned: true });
  }
);

3. Using "Everything Except" Rules

Wrong:

// ❌ There's no way to express "admin.* except admin.users"
// You can't negate permissions in permly
// const result = "admin.* except admin.users"; // Not supported
// ❌ There's no way to express "admin.* except admin.users"
// You can't negate permissions in permly
// const result = "admin.* except admin.users"; // Not supported

Right:

import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["admin.settings", "admin.users"],
  roles: ["moderator"],
  strict: false
});

await perms.sync();

// ✓ Be explicit: grant only what the role needs
await perms.role("moderator").givePermission(
  "admin.settings"
  // Omit admin.users
);

// Check a user with this role
await perms.user(1).assignRole("moderator");
const canManage = await perms.user(1).can("admin.settings"); // true
const canDelete = await perms.user(1).can("admin.users");
canDelete; // false (didn't grant it)
import { createPermissions } from "permly";
import { memoryAdapter } from "permly/memory";

const perms = createPermissions({
  adapter: memoryAdapter(),
  permissions: ["admin.settings", "admin.users"],
  roles: ["moderator"],
  strict: false
});

await perms.sync();

// ✓ Be explicit: grant only what the role needs
await perms.role("moderator").givePermission(
  "admin.settings"
  // Omit admin.users
);

// Check a user with this role
await perms.user(1).assignRole("moderator");
const canManage = await perms.user(1).can("admin.settings"); // true
const canDelete = await perms.user(1).can("admin.users");
canDelete; // false (didn't grant it)