Files
temetro/frontend/lib/access.ts
T
Khalid Abdi 128ce36df2 backend: add appointment/prescription/task RBAC resources
Extend the clinic access-control statements and role grants with
appointment/prescription/task resources (mirrored in the frontend client
AC), and widen the requirePermission type to accept any defined resource.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-07 19:27:55 +03:00

61 lines
1.6 KiB
TypeScript

import { createAccessControl } from "better-auth/plugins/access";
import {
adminAc,
memberAc,
ownerAc,
defaultStatements,
} from "better-auth/plugins/organization/access";
// Mirrors backend/src/lib/access.ts so the client's permission checks
// (organization.hasPermission / checkRolePermission) match the server.
export const statements = {
...defaultStatements,
patient: ["read", "write", "delete"],
appointment: ["read", "write", "delete"],
prescription: ["read", "write", "delete"],
task: ["read", "write", "delete"],
} as const;
export const ac = createAccessControl(statements);
export const owner = ac.newRole({
...ownerAc.statements,
patient: ["read", "write", "delete"],
appointment: ["read", "write", "delete"],
prescription: ["read", "write", "delete"],
task: ["read", "write", "delete"],
});
export const admin = ac.newRole({
...adminAc.statements,
patient: ["read", "write", "delete"],
appointment: ["read", "write", "delete"],
prescription: ["read", "write", "delete"],
task: ["read", "write", "delete"],
});
export const member = ac.newRole({
...memberAc.statements,
patient: ["read", "write"],
appointment: ["read", "write", "delete"],
prescription: ["read", "write", "delete"],
task: ["read", "write", "delete"],
});
export const viewer = ac.newRole({
patient: ["read"],
appointment: ["read"],
prescription: ["read"],
task: ["read"],
});
export const roles = { owner, admin, member, viewer };
// Human-readable labels for the role keys used in the UI.
export const ROLE_LABELS: Record<keyof typeof roles, string> = {
owner: "Owner",
admin: "Admin",
member: "Clinician",
viewer: "Viewer",
};