All posts
frontendarchitecture

Multi-Role Dashboards Without the Permission Spaghetti

Admin, partner, staff, finance. One dashboard, many roles, and the pattern that kept role checks out of every component.

Muhamad Choirul Adam 3 min readPhoto: Unsplash

A dashboard for one role is a set of pages. A dashboard for five roles is a permission system with pages attached. Most of the work I did on e-commerce and partner platforms this year lived in that second category.

The first version of any multi-role dashboard tends to look like this:

function OrderActions({ user }: { user: User }) {
  return (user.role === "admin" || user.role === "finance") && <RefundButton />;
}

It works for a week. Then a new role appears, someone searches the codebase for "finance", misses three places, and a staff account can issue refunds.

Check permissions, not roles

Roles are who someone is. Permissions are what they can do. Components should only ever ask the second question.

Rendering diagram…
permissions.ts
const grants = {
  admin: ["order.view", "order.approve", "order.refund", "partner.manage"],
  finance: ["order.view", "order.refund", "report.export"],
  staff: ["order.view", "order.approve"],
  partner: ["order.view.own"],
} as const satisfies Record<Role, readonly string[]>;
 
export type Permission = (typeof grants)[Role][number];
 
export function can(user: User, permission: Permission) {
  return (grants[user.role] as readonly string[]).includes(permission);
}

Now the button reads can(user, "order.refund"), and adding a role means editing one object. TypeScript catches typos in permission names, which is half the bugs right there.

The server decides. The UI only reflects it

Hiding a button is a convenience, not security. Every action the button triggers needs the same check on the server:

export async function refundOrder(orderId: string) {
  const user = await requireUser();
  if (!can(user, "order.refund")) throw new Forbidden();
  // ...
}

If the client and the server import the same can() and the same grants, they can't drift apart.

Build the navigation from permissions too

The sidebar is where role checks multiply fastest. Give every nav item the permission it needs and filter once:

const nav = [
  { href: "/orders", label: "Orders", needs: "order.view" },
  { href: "/partners", label: "Partners", needs: "partner.manage" },
  { href: "/reports", label: "Reports", needs: "report.export" },
] satisfies { href: string; label: string; needs: Permission }[];
 
const visible = nav.filter((item) => can(user, item.needs));

Pair it with the same check in the page itself, so typing the URL directly gets a proper "no access" screen instead of a broken page.

Hide or disable?

A rule that settled a lot of arguments for us:

  • Hide what a role will never be able to do. A partner never needs to see "Manage partners".
  • Disable with a reason what a role can do but not right now. "Refund unavailable: order not yet paid" saves a support ticket.

Test the matrix, not the pages

The bugs live at the intersections. A small table-driven test catches them:

test.each([
  ["staff", "order.refund", false],
  ["finance", "order.refund", true],
  ["partner", "order.approve", false],
] as const)("%s can %s: %s", (role, permission, expected) => {
  expect(can({ role } as User, permission)).toBe(expected);
});

When someone changes a grant, this test is the one that fails, and the diff shows exactly which role gained or lost what. That's the conversation you want to have in review, not in production.