Multi-tenant platform (182 pages, 228 API routes, ~30 modules) built on a deterministic verification core: clinical-trial claims checked against ClinicalTrials.gov registered results and raw event counts (ARR/NNT/RR+CI recomputed in code, oracle-tested), code-enforced exact-span grounding, and multi-source cross-verification. Auth/RBAC/multi-tenancy, document processing at scale (unpdf + Docling), agentic workflows, Claude Science connector, compliance/audit, billing, public API, and more. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
const ORG_STORAGE_KEY = "pt_active_org";
|
|
|
|
// Resolves the caller's role in the active org from the session endpoint,
|
|
// matched against the org id persisted by the console layout's switcher.
|
|
// Returns null while loading or if the lookup fails (edit controls stay hidden).
|
|
export function useActiveOrgRole(): string | null {
|
|
const [role, setRole] = useState<string | null>(null);
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
(async () => {
|
|
try {
|
|
const res = await fetch("/api/auth/session", { cache: "no-store" });
|
|
const body = await res.json().catch(() => null);
|
|
if (cancelled || !body?.success) return;
|
|
const stored =
|
|
typeof window !== "undefined"
|
|
? window.localStorage.getItem(ORG_STORAGE_KEY)
|
|
: null;
|
|
const orgs: { id: string; role: string }[] = body.data.orgs ?? [];
|
|
const match = orgs.find((o) => o.id === stored) ?? orgs[0];
|
|
setRole(match?.role ?? null);
|
|
} catch {
|
|
// Leave role null; edit controls stay hidden.
|
|
}
|
|
})();
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, []);
|
|
return role;
|
|
}
|
|
|
|
// Roles that may create/edit/run reports and schedules (editor and above).
|
|
export const EDITOR_ROLES = new Set(["owner", "admin", "editor"]);
|
|
|
|
export function canEdit(role: string | null): boolean {
|
|
return role !== null && EDITOR_ROLES.has(role);
|
|
}
|