Nevidna CAPTCHA za React & Next.js

NPM paket s podporo za TypeScript, React Hooks API in združljivostjo z Next.js SSR. Le 3KB gzipped.

Integracija React CAPTCHA

Izkušnja razvijalca

Nativni TypeScript – popolna tipska varnost
React Hooks API – Hook useSilentShield()
Združljiv z Next.js SSR – deluje z App Routerjem
Velikost paketa: le 3KB gzipped
Tree-shakeable – samo tisto, kar potrebujete
Nič odvisnosti – brez odvečne kode

Primeri kode

Namestitev

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

Provider vzorec

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

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

Integrirajte z React zdaj

npm install @silentshield/react – pripravljeno v 5 minutah.