Next.js
Env
Provider (App Router)
KeverdWrapper in app/layout.tsx.
Client collect
Client → /api/login request JSON
visitor.requestId is the collect event_id.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
App Router with @keverdjs/react and server verify
NEXT_PUBLIC_KEVERD_PUBLIC_KEY=kv_pk_test_…
KEVERD_SECRET_KEY=kv_sk_test_…
npm install @keverdjs/react @keverdjs/node
// app/components/KeverdWrapper.tsx
'use client';
import { KeverdProvider } from '@keverdjs/react';
export function KeverdWrapper({ children }: { children: React.ReactNode }) {
return (
<KeverdProvider apiKey={process.env.NEXT_PUBLIC_KEVERD_PUBLIC_KEY!}>
{children}
</KeverdProvider>
);
}
KeverdWrapper in app/layout.tsx.
'use client';
import { useKeverdVisitorData } from '@keverdjs/react';
export default function LoginPage() {
const { getData, isLoading } = useKeverdVisitorData({ immediate: false });
async function login() {
const visitor = await getData();
await fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ eventId: visitor.requestId }),
});
}
return (
<button disabled={isLoading} onClick={() => void login()}>
Continue
</button>
);
}
/api/login request JSON{
"eventId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
visitor.requestId is the collect event_id.
// app/api/login/route.ts
import { Keverd } from '@keverdjs/node';
import { NextResponse } from 'next/server';
const keverd = new Keverd({ secretKey: process.env.KEVERD_SECRET_KEY! });
export async function POST(req: Request) {
const { eventId } = await req.json();
const decision = await keverd.verify(eventId);
if (decision.action === 'block') {
return NextResponse.json(
{ error: 'Blocked', reasons: decision.reasons },
{ status: 403 },
);
}
return NextResponse.json({
ok: true,
visitorId: decision.visitor_id,
timesSeen: decision.times_seen,
isNew: decision.is_new,
});
}
verify request JSON (SDK → API){
"event_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
{
"ok": true,
"visitorId": "kvd_…",
"timesSeen": 3,
"isNew": false
}
{
"error": "Blocked",
"reasons": [
{
"code": "VPN_DETECTED",
"explanation": "The connection appears to route through a VPN.",
"evidence": {}
}
]
}
