Overview
In this quickstart, you’ll add Fingerprint to a new Next.js project and identify the user’s device. The example use case in this quickstart is stopping new account fraud, where attackers create multiple fake accounts to abuse promotions, exploit systems, or evade bans. However, the steps you’ll follow apply to most use cases. By identifying the device behind each sign-up attempt, login, or transaction, you can flag and block suspicious users early. This guide focuses on the frontend integration. You’ll install the Fingerprint React SDK and initialize the JavaScript agent to generate an event ID to send to your backend for analysis. To see how to implement fraud prevention with this ID, continue to one of the backend quickstarts after completing this quickstart.Estimated time: < 10 minutes
Prerequisites
Before you begin, make sure you have the following:- Node.js (v20 or later) and npm installed
- Your favorite code editor
- Basic knowledge of Next.js and React
This quickstart only covers the frontend setup. You’ll need a backend
server to receive and process the device identification event to enable
fraud detection. Check out one of our backend quickstarts
after completing this quickstart.
1. Create a Fingerprint account and get your API key
- Sign up for a free Fingerprint trial if you don’t already have an account.
- After signing in, go to the API keys page in the dashboard.
- Copy your public API key; you’ll need it to initialize the JavaScript agent.
2. Set up your project
To get started, scaffold a new Next.js app. If you already have a project you want to use, you can skip to the next section.- Create a new Next.js project:
Terminal
- When prompted, select the default options (TypeScript, ESLint, Tailwind CSS, App Router).
-
Open the
fingerprint-nextjs-quickstartfolder in your code editor. To run your project:
Terminal
- In your browser, go to http://localhost:3000, and you should see the Next.js welcome page.
3. Set up your account creation form
- Before adding Fingerprint, create a new client component at
app/components/CreateAccountForm.tsxwith the following:
app/components/CreateAccountForm.tsx
- Open
app/globals.cssand add these classes to the end of the file:
app/globals.css
- Create a client component for the home page at
app/components/HomePage.tsx:
app/components/HomePage.tsx
- Update
app/page.tsxto use the new component:
app/page.tsx
4. Install and initialize the JavaScript agent
- To integrate Fingerprint into your Next.js app, add the Fingerprint React SDK via npm:
Terminal
- Import and initialize the Fingerprint provider in
app/layout.tsx:
app/layout.tsx
- Wrap your app with the Fingerprint provider in
app/layout.tsx:
app/layout.tsx
- Set
PUBLIC_API_KEYto the public API key from the Fingerprint dashboard.
5. Trigger visitor identification
Now that the JavaScript agent is initialized, you can identify the visitor only when needed. In this case, that’s when the user taps the Create Account button. When making the visitor identification request, you will receive the visitor ID as well as an event ID. Instead of using the visitor ID returned directly on the frontend (which could be tampered with), you’ll send the event ID to your backend. This ID is unique to each identification event. Your server can then use the Fingerprint Events API to retrieve complete identification data, including the trusted visitor ID and other actionable insights like whether they are using a VPN or are a bot.- In
app/components/HomePage.tsx, import Fingerprint’suseVisitorDatahook and add the identification logic:
app/components/HomePage.tsx
getData(): A function to trigger visitor identification on demand.isLoading: A flag to monitor visitor identification progress.
getData() method.
Check our GitHub repo for available useVisitorData options.
6. Test the app
- If your dev server isn’t already running, start it with:
Terminal
- In your browser, go to http://localhost:3000.
- If you have any ad blockers, turn them off for localhost. View the documentation to learn how to protect your Fingerprint implementation from ad blockers in production.
- Enter a username and password, then click Create Account.
- Open the developer console in your browser and you should see the visitor ID and event ID in the output:
Output
Next steps
To use the identification data for fraud detection (like blocking repeat fake account creation attempts), you’ll need to send theevent_id to your backend. From there, your server can call the Fingerprint Events API to retrieve the full visitor information data and use it to make decisions and prevent fraud.
Check out these related resources: