Niewidoczna CAPTCHA dla React & Next.js

Pakiet NPM z obsługą TypeScript, API React Hooks i kompatybilnością SSR Next.js. Tylko 3KB gzipped.

Integracja CAPTCHA React

Doświadczenie programisty

Natywny TypeScript – pełne bezpieczeństwo typów
API React Hooks – Hook useSilentShield()
Kompatybilny z SSR Next.js – działa z App Router
Rozmiar bundle: tylko 3KB gzipped
Tree-shakeable – tylko to, czego potrzebujesz
Zero zależności – bez zbędnego kodu

Przykłady kodu

Instalacja

npm install @silentshield/react

API React Hook

import { useSilentShield } from '@silentshield/react';

function ContactForm() {
  const { verify, isVerifying } = useSilentShield({
    siteKey: 'YOUR_SITE_KEY',
  });

  const handleSubmit = async (e: FormEvent) => {
    e.preventDefault();
    const token = await verify();

    // Send token to backend
    await fetch('/api/contact', {
      method: 'POST',
      body: JSON.stringify({ ...formData, token }),
    });
  };

  return (
    <form onSubmit={handleSubmit}>
      {/* Your form fields */}
      <button disabled={isVerifying}>
        Submit
      </button>
    </form>
  );
}

Next.js App Router

// app/api/contact/route.ts
import { verifySilentShield } from '@silentshield/node';

export async function POST(req: Request) {
  const { token, ...data } = await req.json();

  const result = await verifySilentShield({
    secret: process.env.SILENTSHIELD_SECRET!,
    token,
  });

  if (!result.success) {
    return Response.json(
      { error: 'Bot detected' },
      { status: 403 }
    );
  }

  // Process form data...
}

Wzorzec Provider

import { SilentShieldProvider } from '@silentshield/react';

function App() {
  return (
    <SilentShieldProvider siteKey="YOUR_SITE_KEY">
      <MyApp />
    </SilentShieldProvider>
  );
}

Zintegruj z React teraz

npm install @silentshield/react – gotowe w 5 minut.