Neviditeľná CAPTCHA pre React & Next.js

NPM balíček s podporou TypeScript, React Hooks API a kompatibilitou s Next.js SSR. Iba 3KB gzipped.

Integrácia React CAPTCHA

Vývojársky zážitok

Natívny TypeScript – plná typová bezpečnosť
React Hooks API – Hook useSilentShield()
Kompatibilný s Next.js SSR – funguje s App Router
Veľkosť balíčku: iba 3KB gzipped
Tree-shakeable – iba to, čo potrebujete
Žiadne závislosti – žiadny bloat

Príklady kódu

Inštalácia

npm install @silentshield/react

React Hook API

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...
}

Vzor Provider

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

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

Integrujte s React teraz

npm install @silentshield/react – pripravené za 5 minút.