> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fingerprint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Next.js Quickstart

> Get started using the Fingerprint React SDK with Next.js

## Overview

In this quickstart, you'll add Fingerprint to a new [Next.js](https://nextjs.org/) 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](/docs/react) 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](/docs/server-quickstarts-overview) after completing this quickstart.**

> Estimated time: \< 10 minutes

## Prerequisites

Before you begin, make sure you have the following:

* [Node.js](https://nodejs.org/) (v20 or later) and npm installed
* Your favorite code editor
* Basic knowledge of [Next.js](https://nextjs.org/) and React

<Note>
  This quickstart only covers the **frontend setup**. You'll need a [backend
  server](/reference/server-sdks) to receive and process the device identification event to enable
  fraud detection. Check out one of our [backend quickstarts](/docs/server-quickstarts-overview)
  after completing this quickstart.
</Note>

## 1. Create a Fingerprint account and get your API key

1. [Sign up](https://dashboard.fingerprint.com/signup) for a free Fingerprint trial if you don't already have an account.
2. After signing in, go to the [**API keys**](https://dashboard.fingerprint.com/api-keys) page in the dashboard.
3. 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.

1. Create a new Next.js project:

```bash Terminal theme={"theme":"github-dark-dimmed"}
npx create-next-app@latest fingerprint-nextjs-quickstart
cd fingerprint-nextjs-quickstart
```

2. When prompted, select the default options (TypeScript, ESLint, Tailwind CSS, App Router).

3. Open the `fingerprint-nextjs-quickstart` folder in your code editor. To run your project:

```bash Terminal theme={"theme":"github-dark-dimmed"}
npm run dev
```

4. In your browser, go to [http://localhost:3000](http://localhost:3000/), and you should see the Next.js welcome page.

## 3. Set up your account creation form

1. Before adding Fingerprint, create a new client component at `app/components/CreateAccountForm.tsx` with the following:

```tsx app/components/CreateAccountForm.tsx theme={"theme":"github-dark-dimmed"}
"use client";

import { useState } from "react";

interface CreateAccountFormProps {
  isLoading?: boolean;
  handleSubmit?: () => void;
}

export default function CreateAccountForm(props: CreateAccountFormProps) {
  const [username, setUsername] = useState("");
  const [password, setPassword] = useState("");
  return (
    <div className="wrapper">
      <h1>Create an account</h1>
      <div className="input-group">
        <label htmlFor="username">Username</label>
        <input
          id="username"
          value={username}
          onChange={(e) => setUsername(e.target.value)}
          type="text"
          placeholder="Username"
          required
        />
      </div>
      <div className="input-group">
        <label htmlFor="password">Password</label>
        <input
          id="password"
          value={password}
          onChange={(e) => setPassword(e.target.value)}
          type="password"
          placeholder="Password"
          required
        />
      </div>
      <button disabled={props.isLoading} onClick={props.handleSubmit}>
        {props.isLoading ? "Loading…" : "Create Account"}
      </button>
    </div>
  );
}
```

2. Open `app/globals.css` and add these classes to the end of the file:

```css app/globals.css theme={"theme":"github-dark-dimmed"}
.wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 1rem;
  padding: 2rem 3rem;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  box-sizing: border-box;
}

@layer base {
  h1 {
    font-size: 2rem;
    font-weight: 600;
    text-align: center;
    margin: 0;
  }
}

input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.input-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

button {
  background-color: #f35b22;
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
```

3. Create a client component for the home page at `app/components/HomePage.tsx`:

```tsx app/components/HomePage.tsx theme={"theme":"github-dark-dimmed"}
"use client";

import CreateAccountForm from "./CreateAccountForm";

export default function HomePage() {
  return (
    <main>
      <CreateAccountForm />
    </main>
  );
}
```

4. Update `app/page.tsx` to use the new component:

```tsx app/page.tsx theme={"theme":"github-dark-dimmed"}
import HomePage from "./components/HomePage";

export default function Home() {
  return <HomePage />;
}
```

## 4. Install and initialize the JavaScript agent

1. To integrate Fingerprint into your Next.js app, add the Fingerprint React SDK via npm:

```bash Terminal theme={"theme":"github-dark-dimmed"}
npm install @fingerprint/react
```

*Note: This quickstart is written for version 3.x of the Fingerprint React SDK*

2. Import and initialize the Fingerprint provider in `app/layout.tsx`:

```tsx app/layout.tsx theme={"theme":"github-dark-dimmed"}
import { FingerprintProvider } from "@fingerprint/react";
```

3. Wrap your app with the Fingerprint provider in `app/layout.tsx`:

```tsx app/layout.tsx theme={"theme":"github-dark-dimmed"}
export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body>
        <FingerprintProvider // [!code ++:5]
          apiKey="PUBLIC_API_KEY"
          region="us" // Ensure this matches your workspace region
          // For more information, see https://docs.fingerprint.com/docs/regions
        >
          {children}
          {/* [!code ++] */}
        </FingerprintProvider>
      </body>
    </html>
  );
}
```

4. Set `PUBLIC_API_KEY` to the public API key from the [Fingerprint dashboard](https://dashboard.fingerprint.com/api-keys).

*Note: For production, consider using* *[Next.js environment variables](https://nextjs.org/docs/app/building-your-application/configuring/environment-variables)* *to configure the key.*

## 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](/reference/server-api-v4-get-event) 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.

1. In `app/components/HomePage.tsx`, import Fingerprint's `useVisitorData` hook and add the identification logic:

```tsx app/components/HomePage.tsx theme={"theme":"github-dark-dimmed"}
"use client";

import CreateAccountForm from "./CreateAccountForm";
import { useVisitorData } from "@fingerprint/react"; // [!code ++]

export default function HomePage() {
  const { getData, isLoading } = useVisitorData({ immediate: false }); // [!code ++]

  // [!code ++:5]
  async function handleSubmit() {
    const { visitor_id, event_id } = await getData();

    console.log("Visitor ID:", visitor_id);
    console.log("Event ID:", event_id);

    // Example of how you could send the event_id and form data to your server:
    // await fetch("http://localhost:3000/api/create-account", {
    //   method: "POST",
    //   headers: { "Content-Type": "application/json" },
    //   body: JSON.stringify({
    //     username: username.value,
    //     password: password.value,
    //     event_id,
    //   }),
    // });
  } // [!code ++]

  return (
    <main>
      {/* [!code ++] */}
      <CreateAccountForm isLoading={isLoading} handleSubmit={handleSubmit} />
    </main>
  );
}
```

This gives you:

* `getData()`: A function to trigger visitor identification on demand.
* `isLoading`: A flag to monitor visitor identification progress.

By setting immediate to false you're triggering device identification only when needed with the `getData()` method.

*Check our* *[GitHub repo](https://github.com/fingerprintjs/react)* *for available useVisitorData options.*

## 6. Test the app

1. If your dev server isn't already running, start it with:

```bash Terminal theme={"theme":"github-dark-dimmed"}
npm run dev
```

2. In your browser, go to [http://localhost:3000](http://localhost:3000/).
3. If you have any ad blockers, turn them off for localhost. View the [documentation](/docs/protecting-the-javascript-agent-from-adblockers) to learn how to protect your Fingerprint implementation from ad blockers in production.
4. Enter a username and password, then click **Create Account**.
5. Open the developer console in your browser and you should see the visitor ID and event ID in the output:

```text Output theme={"theme":"github-dark-dimmed"}
Visitor ID: JkLmNoPqRsTuVwXyZaBc
Event ID: 1234566477745.abc1GS
```

## Next steps

To use the identification data for fraud detection (like blocking repeat fake account creation attempts), you'll need to send the `event_id` to your [backend](/docs/server-quickstarts-overview). From there, your server can call the [Fingerprint Events API](/reference/server-api-v4-get-event) to retrieve the full visitor information data and use it to make decisions and prevent fraud.

Check out these related resources:

* [React SDK reference](https://github.com/fingerprintjs/react)
* [Node.js backend quickstart](/docs/node-server-quickstart)
* [API reference for the Events endpoint](/reference/server-api-v4-get-event)
* [Use case tutorial: Detecting new account fraud](/docs/new-account-fraud-use-case-tutorial)
* [Protecting from client-side tampering and replay attacks](/docs/protecting-from-client-side-tampering)
