Integrations
Web frameworks
Enforce ReQlo decisions in Next.js, FastAPI, Express and Fastify server code.
The pattern is the same everywhere: authenticate the user, load authoritative data, call enforce on the server, and only then run the action. Denials return 403; ReQlo errors return 503, never the action.
Call ReQlo only from server code: route handlers, server actions or server components. Never import the client into a client component.
lib/reqlo.ts
import "server-only";
import { Reqlo } from "@reqlo/sdk";
export const reqlo = new Reqlo({ apiKey: process.env.REQLO_API_KEY! });app/api/agent/tools/publish/route.ts
import { NextResponse } from "next/server";
import { ReqloDeniedError } from "@reqlo/sdk";
import { reqlo } from "@/lib/reqlo";
import { getSession } from "@/lib/auth";
export async function POST(req: Request) {
const session = await getSession(); // verified
if (!session) return NextResponse.json({ error: "Unauthenticated" }, { status: 401 });
const { documentId, visibility } = await req.json();
const doc = await db.documents.find(documentId);
try {
await reqlo.enforce({
agent: { id: "agt_editor" },
subject: { id: session.userId, kind: "user" },
action: "documents.publish",
resource: { type: "document", id: doc.id, attributes: { owner_id: doc.ownerId } },
context: { document_classification: doc.classification, requested_visibility: visibility },
});
} catch (e) {
if (e instanceof ReqloDeniedError) return NextResponse.json({ error: "Not allowed" }, { status: 403 });
return NextResponse.json({ error: "Authorization unavailable" }, { status: 503 }); // fail closed
}
await db.documents.publish(doc.id, visibility);
return NextResponse.json({ ok: true });
}The server-only import makes the build fail if the client is ever imported into browser code.
Something wrong or unclear? Report an issue with this page.