@agentgatepkg/nextjs
v0.1.0
Published
AgentGate Next.js SDK — middleware and server-side AI agent verification
Downloads
56
Maintainers
Readme
@agentgatepkg/nextjs
Next.js middleware and server-side utilities for AgentGate AI agent verification.
Install
npm install @agentgatepkg/nextjsMiddleware — Protect Routes
// middleware.ts
import { createAgentGateMiddleware } from "@agentgatepkg/nextjs";
export default createAgentGateMiddleware({
endpoint: "http://localhost:8080",
protectedPaths: ["/api/*", "/agent/*"],
redirectUrl: "/blocked",
});
export const config = {
matcher: ["/api/:path*", "/agent/:path*"],
};Server-Side Verification
// app/api/protected/route.ts
import { verifyAgent } from "@agentgatepkg/nextjs";
export async function GET(request: Request) {
const result = await verifyAgent({
endpoint: "http://localhost:8080",
request,
});
if (!result.isAgent) {
return Response.json({ error: "Not verified" }, { status: 403 });
}
return Response.json({ data: "secret" });
}Re-exports
This package re-exports everything from @agentgatepkg/react for convenience:
import {
AgentGateProvider,
useAgentGate,
AgentGateGuard,
} from "@agentgatepkg/nextjs";Exports
| Export | Description |
|--------|-------------|
| createAgentGateMiddleware | Next.js middleware factory |
| verifyAgent | Server-side verification function |
| AgentGateProvider | React context provider (re-export) |
| useAgentGate | React hook (re-export) |
| AgentGateGuard | Guard component (re-export) |
Peer Dependencies
next>= 14.0.0react>= 18.0.0
Requirements
- AgentGate backend running (setup guide)
Links
License
MIT
