Socket
Book a DemoInstallSign in
Socket

@centinel/nextjs

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@centinel/nextjs

Package designed to add Centinel Analytica functionality to Next.js applications

latest
Source
npmnpm
Version
1.2.1
Version published
Weekly downloads
354
51.93%
Maintainers
1
Weekly downloads
 
Created
Source

Centinel Analytica Next.js Integration

Bot protection middleware for Next.js applications.

Installation

npm install @centinel/nextjs

Setup

1. Environment Variables

CENTINEL_SITE_KEY=your_site_key_here
CENTINEL_SECRET_KEY=your_secret_key_here
NEXT_PUBLIC_CENTINEL_SITE_KEY=your_site_key_here

2. Client Script

// app/layout.tsx
import { CentinelLayout } from '@centinel/nextjs';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>
        <CentinelLayout siteKey={process.env.CENTINEL_SITE_KEY!}>
          {children}
        </CentinelLayout>
      </body>
    </html>
  );
}

3. Middleware

Simple Middleware

import { createCentinelMiddlewareFromEnv } from '@centinel/nextjs';
import { NextRequest } from 'next/server';

const centinelMiddleware = createCentinelMiddlewareFromEnv();

export default async function middleware(request: NextRequest) {
  const result = await centinelMiddleware(request);
  return result.response;
}

export const config = {
  matcher: ['/api/:path*', '/dashboard/:path*']
};

With Multiple Middlewares

import { createCentinelMiddleware } from '@centinel/nextjs';
import { NextRequest, NextResponse } from 'next/server';

const centinelMiddleware = createCentinelMiddleware({
  siteKey: process.env.CENTINEL_SITE_KEY!,
  secretKey: process.env.CENTINEL_SECRET_KEY!
});

export default async function middleware(request: NextRequest) {
  const result = await centinelMiddleware(request);

  if (result.should_intercept) {
    return result.response;
  }

  // Your other middleware logic
  return NextResponse.next();
}

export const config = {
  matcher: ['/api/:path*', '/dashboard/:path*']
};

Manual Validation (API Routes)

// app/api/login/route.ts
import { createRequestValidatorFromEnv } from '@centinel/nextjs';
import { NextRequest, NextResponse } from 'next/server';

const { isBot } = createRequestValidatorFromEnv();

export async function POST(request: NextRequest) {
  if (await isBot(request)) {
    return NextResponse.json({ error: 'Blocked' }, { status: 403 });
  }
  return handleLogin(request);
}

Advanced

CentinelResult

interface CentinelResult {
  response: NextResponse;
  decision: 'allow' | 'block' | 'redirect' | 'not_matched';
  should_intercept: boolean;
}
  • should_intercept: trueblock or redirect (return immediately)
  • should_intercept: falseallow or not_matched (continue)

CentinelMiddleware Class

import { CentinelMiddleware } from '@centinel/nextjs';

const centinel = new CentinelMiddleware({
  siteKey: process.env.CENTINEL_SITE_KEY!,
  secretKey: process.env.CENTINEL_SECRET_KEY!,
  timeout: 1000,  // ms (default: 500)
  debugMode: true
});

const result = await centinel.validate({ request });
export async function POST(request: NextRequest) {
  if (!request.cookies.get('_centinel')) {
    return NextResponse.json({ error: 'Blocked' }, { status: 403 });
  }
  // ...
}

Keywords

bot

FAQs

Package last updated on 03 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts