AbuseGraphDocs
Guides

AbuseGraph + NextAuth

Score Auth.js createUser and signIn events with createCheckClient — forward browser toCheckBody for a full score.

Quick path

  1. Install @abusegraph/sdk and @abusegraph/server; paste keys from the console.
  2. Collect browser signals on auth forms → toCheckBody → pass into callbacks.
  3. Wire createUser / signIn events to createCheckClient.check.

Keys

KeyEnvUse
SecretABUSEGRAPH_SECRET_KEY (sk_test_… / sk_live_…)Server /api/v1/check
PublishableNEXT_PUBLIC_ABUSEGRAPH_PUBLISHABLE_KEY (pk_test_…)Browser SDK
SiteABUSEGRAPH_SITEDNS-verified domain

Free includes 1,000 live API checks / month after DNS verify. Test keys never bill.

Env

ABUSEGRAPH_SITE=yourdomain.com
ABUSEGRAPH_CHECK_URL=https://abusegraph.com/api/v1/check
ABUSEGRAPH_SECRET_KEY=sk_test_…
ABUSEGRAPH_SECRET_KEY_TEST=sk_test_…
NEXT_PUBLIC_ABUSEGRAPH_PUBLISHABLE_KEY=pk_test_…

Use sk_live_… / pk_live_… in production after DNS verify.

Server check

Use @abusegraph/server createCheckClient. Events: signup | login | password_reset | email_change. Optional sessionId.

import { createCheckClient } from "@abusegraph/server"

const abusegraph = createCheckClient({
  secretKey:
    process.env.NODE_ENV === "production"
      ? process.env.ABUSEGRAPH_SECRET_KEY! // sk_live_…
      : process.env.ABUSEGRAPH_SECRET_KEY_TEST ??
        process.env.ABUSEGRAPH_SECRET_KEY!, // sk_test_…
  site: process.env.ABUSEGRAPH_SITE!,
})

init + collect + evaluate + toCheckBody — NEVER bare sdk.check() alone as the authoritative decision.

import { init } from "@abusegraph/sdk"

const sdk = init({
  publicKey: process.env.NEXT_PUBLIC_ABUSEGRAPH_PUBLISHABLE_KEY!, // pk_test_…
})

export async function collectForAuth(
  email: string,
  event: "signup" | "login" | "password_reset" | "email_change",
) {
  const collected = await sdk.collect()
  const edge = await sdk.evaluate(collected, { email })
  return sdk.toCheckBody(collected, {
    email,
    event,
    verdictToken: edge.verdictToken.token,
  })
}

Auth.js / NextAuth events

Merge browserFields from the client (hidden field / cookie):

// auth.ts
import { createCheckClient } from "@abusegraph/server"

const abusegraph = createCheckClient({
  secretKey: process.env.ABUSEGRAPH_SECRET_KEY!,
  site: process.env.ABUSEGRAPH_SITE!,
})

export const authConfig = {
  events: {
    async createUser({ user, request }) {
      if (!user.email) return
      const browserFields = /* from request */ {}
      const result = await abusegraph.check({
        email: user.email,
        userId: user.id,
        event: "signup",
        ...browserFields,
      })
      if (result.verdict === "block") {
        // delete user — do not leave a live session
      }
    },
    async signIn({ user, request }) {
      if (!user.email) return
      const result = await abusegraph.check({
        email: user.email,
        userId: user.id,
        event: "login",
      })
      if (result.verdict === "block") {
        throw new Error("Sign-in blocked")
      }
    },
  },
}

Lifecycle events

  • loginsignIn event with event: "login".
  • password_reset — call check in your reset route with event: "password_reset".
  • email_change — call after email update with event: "email_change".

Platform

Lists, rules, and linked accounts apply on every check — configure in the console. Optional session: POST /api/v1/session. Native apps: iOS, Android, React Native.

Verify

Sign up once with sk_test_…, then open Activity. Blocked users should not retain a session.