framework
Browser fingerprinting in Next.js
Add browser fingerprinting and bot, disposable email and IP checks to a Next.js signup form: collect in a client component, check in a Server Action with the visitor’s IP.
This guide adds OpenFingerprint to a Next.js signup form with the App Router. The browser runs the SDK, which posts its evidence to the API's public identify listener, and puts the identification ID it gets back in the form; a Server Action sends the identification ID, the email address and the visitor's IP to the check API with your secret key, and decides what to do with the answer. The listener sees the browser connect, and your key never reaches the browser.
1. Install the SDK and add your key
npm install @openfingerprint/sdkCreate a secret key under API keys in the dashboard and add it to .env.local, without a NEXT_PUBLIC_ prefix so it stays on the server:
OPENFINGERPRINT_KEY=of_…2. Identify in the browser
Start watching and collecting when the form mounts, so the identification is usually ready by the time someone presses the button, and add it to the form data on submit. Collect only once your disclosure or consent requirements are met.
// app/signup/signup-form.tsx
'use client';
import { identify, watch, type Identification } from '@openfingerprint/sdk';
import { useEffect, useRef } from 'react';
import { signUp } from './actions';
export function SignupForm() {
const collecting = useRef<Promise<Identification> | null>(null);
useEffect(() => {
watch();
collecting.current = identify({ endpoint: 'https://events.openfingerprint.com/v1/identify' });
}, []);
async function action(formData: FormData) {
const result = await collecting.current?.catch(() => null);
if (result?.identificationId) formData.set('of_identification', result.identificationId);
await signUp(formData);
}
return (
<form action={action}>
<input name="email" type="email" required />
<button>Sign up</button>
</form>
);
}If posting fails, identificationId is null and the form still submits. The server omits that ID; email and IP checks continue, and browser evidence stays unknown, not suspicious. There is no local-evidence fallback. If your site sets a Content-Security-Policy, allow https://events.openfingerprint.com in connect-src.
3. Check on the server
The Server Action calls POST /v1/check with the identification ID, the email address and the visitor's IP. The API never reads an IP from the connection: your server passes the address it saw. Vercel and most hosting platforms overwrite x-forwarded-for with the address they received the request from; behind your own proxy, take the address that proxy added, not a value the browser could have sent.
// app/signup/actions.ts
'use server';
import { headers } from 'next/headers';
type Check = {
visitorId?: string;
replayed?: boolean;
automation?: boolean;
spoofing?: boolean;
disposable?: boolean;
tor?: boolean;
vpn?: boolean;
};
async function check(input: { identificationId?: string | null; email: string; ip?: string }) {
try {
const response = await fetch('https://api.openfingerprint.com/v1/check', {
method: 'POST',
headers: {
'content-type': 'application/json',
'x-api-key': process.env.OPENFINGERPRINT_KEY!
},
body: JSON.stringify(input),
signal: AbortSignal.timeout(5000)
});
return response.ok ? ((await response.json()) as Check) : {};
} catch {
return {};
}
}
export async function signUp(formData: FormData) {
const email = String(formData.get('email') ?? '');
const identificationId = formData.get('of_identification');
const ip = (await headers()).get('x-forwarded-for')?.split(',')[0].trim();
const result = await check({
identificationId:
typeof identificationId === 'string' && identificationId ? identificationId : null,
email,
ip
});
if (result.disposable) {
return { error: 'Please use a permanent email address.' };
}
const verifyFirst = result.automation || result.spoofing || result.replayed || result.tor;
// create the account, store result.visitorId on it only when present, and ask for
// email verification before any free credits when verifyFirst is true
}A failed or slow check returns {}, so signups keep working when the API can't be reached.
4. Decide
The response is flat: a key is present only when it is known, so a missing disposable means unknown, never "clean".
disposableis strong evidence: ask for another address.automation,spoofing(the browser's report contradicts its headers or TLS handshake, as when a script poses as a browser),replayed(the same identification looked up twice) andtorare reasons to ask for more proof, such as email verification or a challenge, not to block.behaviorlists input patterns sincewatch(), such asclicks_without_movement. Keyboard users, autofill and password managers match some of them, so treat them as context for your own rules.visitorIdis a random server-issued browser grouping, not a fingerprint hash. Store it only when present and count recent accounts with the same ID. It can split repeat visits or merge indistinguishable browsers; missing IDs stay unknown.identificationIdreferences one hour-long observation and is not the value to store on accounts.
The free trial abuse guide has an example policy, and the check API reference lists every key.
Self-hosting
The SDK and the check API are MIT licensed. To run the API yourself, follow Deploy with Helm, replace the URL with your own service, drop the x-api-key header, and point endpoint at your own mandatory public identify listener. Configure identify.origins and identify.certificates, and use TCP passthrough so it sees the browser's TLS handshake. The internal check API has no authentication, so keep it on a private network. To receive visitor IDs, configure PostgreSQL, apply the visitor migrations and keep the deployment namespace stable. A single-customer install can set postgres.visitorScope; shared hosts should require backend-derived customer scopes. See visitor IDs and scopes.