caelum0x 695a365ae4 feat: PaperTrail — enterprise evidence-verification platform
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>
2026-07-08 07:21:22 +03:00

59 lines
1.4 KiB
TypeScript

import { getPool } from "@/lib/db";
import { getSessionUserId } from "@/lib/auth/session";
import { ok, fail } from "@/lib/api/response";
import type { Role } from "@/lib/authz/rbac";
export const runtime = "nodejs";
export interface SessionOrg {
id: string;
name: string;
slug: string;
role: Role;
}
export interface SessionPayload {
user: { id: string; email: string; name: string | null };
orgs: SessionOrg[];
}
export async function GET(): Promise<Response> {
try {
const userId = await getSessionUserId();
if (!userId) {
return fail("Not authenticated.", 401);
}
const pool = getPool();
const userRes = await pool.query(
`select id, email, name from users where id = $1`,
[userId]
);
if (userRes.rows.length === 0) {
return fail("Not authenticated.", 401);
}
const user = userRes.rows[0];
const orgsRes = await pool.query(
`select o.id, o.name, o.slug, m.role
from memberships m
join orgs o on o.id = m.org_id
where m.user_id = $1
order by m.created_at asc`,
[userId]
);
const payload: SessionPayload = {
user: { id: user.id, email: user.email, name: user.name ?? null },
orgs: orgsRes.rows.map((r) => ({
id: r.id,
name: r.name,
slug: r.slug,
role: r.role as Role,
})),
};
return ok(payload);
} catch {
return fail("Failed to load session.", 500);
}
}