Before you start
An existing Next.js 14, 15 or 16 application with React 18/19. Keep Private API Keys in Server Actions or route handlers only. Register and verify the website domain in your analytics dashboard. Use credentials from the same domain and environment as the browser check. For a fresh account, start with Quick Start.Get your credentials
Copy the Public Key for your domain from Integration > API keys. A public frontend environment variable may contain this key, but never a Private API Key or webhook signing secret.Install the SDK
yarn add or pnpm add with the same package names if your project uses that package manager. Framework packages remain the application’s responsibility.
Add the integration
With the App Router: a provider in the root layout, a signup page whose form sends arequestId, a
Server Action that reads the verdict, a store for used request IDs, and a route handler for webhooks.
The imports use the @/ alias that create-next-app sets up.
identify() from useIdentify() never rejects: it resolves the result, or null with the reason in
error. A second submit while the identification runs gets the same one, so a double click costs one
identification.
Add https://<your domain>/api/shieldlabs/webhook as a webhook endpoint in the analytics dashboard,
put its signing secret in SHIELDLABS_WEBHOOK_SECRET and press Verify: the handler answers the
webhook.ping with 200.
getIdentification() waits until the verdict is stored, which is usually 1 to 3 seconds after
identify(). Start the identification when the user begins the action to save that time
(Identify when the user begins the action ).
examples/app-router is a complete app built this way.
Test the complete flow
- Run the application on the registered HTTPS domain with its Public Key.
- Trigger the protected form once and check that a Request ID is sent to your own backend.
- Retrieve that same ID using a server SDK or locate it in the analytics dashboard.
- Test a missing ID and an agent load failure: your backend must treat the action as unverified.
/api/signup routes shown in examples belong to your application; they are not ShieldLabs API endpoints. Connect one of the server quick starts before testing the full action. A successful browser call does not prove scoring is complete.
Troubleshooting
- No History row: confirm the registered domain, credential/environment match and that the browser remained open while collectors posted.
- Missing or pending verdict: scoring is asynchronous. The server helper waits within a bounded budget; handle a missing result and API errors explicitly.
- Authentication error: use the Private API Key for History, not a Public Key, Management Secret Key or MCP OAuth token.
- Invalid webhook signature: verify the original raw bytes with the endpoint’s full signing secret, before trusting parsed JSON.