mirror of
https://github.com/temetro/temetro.git
synced 2026-08-04 07:58:13 +00:00
6213da9477
Replace the email-invitation flow with admin-provisioned staff accounts and
add role-based access that changes what each member sees.
Backend:
- Enable Better Auth `username` plugin (staff sign in by username); regenerate
auth schema (+ username/displayUsername on user) and migration 0007.
- Add `doctor` and `reception` roles to the access-control RBAC. `reception` is
scoped to scheduling + registration (no `prescription` statement).
- New `/api/staff` route: POST creates a user (auth.api.signUpEmail) and adds
them to the active clinic (auth.api.addMember); GET lists members + usernames.
Gated by requirePermission({ member: ["create"] }).
- Redact clinical PHI for the reception role in the patients service (read,
create and update) so demographics-only is enforced server-side.
Frontend:
- usernameClient + Email|Username tabs on the login form.
- lib/roles.ts: useActiveRole + Better-Auth-permission-driven nav visibility,
default landing, and a route guard (reception -> /appointments, blocked from
clinical routes). Applied to the sidebar, command palette and auth guard.
- Care team page now provisions staff via a two-step Add-team-member dialog
(details -> username/password) hitting /api/staff; removes the email-invite
and pending-invitation UI. New members are contactable from Messages
automatically (they become org members).
- Hide clinical sections of the patient form and the admin-only settings tabs
for non-clinical/non-admin roles.
All permission management stays in Better Auth (per the better-auth skills now
referenced in backend/CLAUDE.md).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
81 lines
2.3 KiB
TypeScript
81 lines
2.3 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"],
|
|
});
|
|
|
|
// doctor (clinician): mirrors backend/src/lib/access.ts — same clinical access
|
|
// as `member`.
|
|
export const doctor = ac.newRole({
|
|
...memberAc.statements,
|
|
patient: ["read", "write"],
|
|
appointment: ["read", "write", "delete"],
|
|
prescription: ["read", "write", "delete"],
|
|
task: ["read", "write", "delete"],
|
|
});
|
|
|
|
// reception (front desk): scheduling + registration only, no clinical records.
|
|
export const reception = ac.newRole({
|
|
...memberAc.statements,
|
|
patient: ["read", "write"],
|
|
appointment: ["read", "write", "delete"],
|
|
task: ["read", "write"],
|
|
});
|
|
|
|
export const viewer = ac.newRole({
|
|
patient: ["read"],
|
|
appointment: ["read"],
|
|
prescription: ["read"],
|
|
task: ["read"],
|
|
});
|
|
|
|
export const roles = { owner, admin, doctor, reception, 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",
|
|
doctor: "Doctor",
|
|
reception: "Reception",
|
|
member: "Clinician",
|
|
viewer: "Viewer",
|
|
};
|