$ show nuxt-modules/turnstile
This is a Nuxt 3 module that integrates Cloudflare Turnstile, a privacy-focused CAPTCHA alternative. It provides a Vue component (`<NuxtTurnstile>`) for client-side rendering of the Turnstile widget, a composable (`useScriptCloudflareTurnstile`) for script loading via `@nuxt/scripts`, and a server-side utility (`verifyTurnstileToken`) for token validation in Nitro endpoints. The module automatically handles script injection, token refresh, and exposes a reset method. It also supports an optional validation endpoint at `/_turnstile/validate`. The architecture follows the standard Nuxt module pattern: `src/module.ts` registers components, composables, and server handlers. External dependencies include Cloudflare's Turnstile API, `@nuxt/scripts`, `@nuxt/kit`, `defu`, and `pathe`. The codebase is well-structured, typed, and includes end-to-end tests with Playwright.
The LLM identified 2 files worth highlighting for reuse:
A clean, isolated server-side utility that validates Turnstile tokens by making a POST request to Cloudflare's siteverify endpoint. It accepts a token, optional H3Event for runtime config, and an AbortSignal. The function is self-contained, uses `$fetch` with proper encoding, and returns a typed `TurnstileValidationResponse`. It can be extracted and reused in any Node.js server (not just Nuxt) with minimal adaptation.
Pure TypeScript type definitions for Turnstile render options and validation responses. Includes detailed JSDoc comments for each field. These types are reusable across any project that interacts with Cloudflare Turnstile, providing a clear contract for both client and server code.