Setup
Open the Cloudflare dashboard
Log in to your Cloudflare dashboard and navigate to Turnstile in the sidebar.
Add a new site
Click Add Site, enter a name, and provide the domain where Nuxt Secure will be deployed. Cloudflare will generate a Site Key and a Secret Key.
How it works
The@nuxtjs/turnstile module (^1.1.1) is listed in the modules array of nuxt.config.ts. It automatically registers a <NuxtTurnstile> component and reads the site key from turnstile.siteKey (populated from NUXT_PUBLIC_TURNSTILE_SITE_KEY).
When the user submits the login form:
- The browser includes a
turnstileTokengenerated by the Turnstile widget. - The server API handler receives the token along with the user’s credentials.
- The server sends the token to Cloudflare’s verification endpoint before processing the login:
server/api/auth/login.post.ts
- If verification fails, the server responds with HTTP
400and the message"Fallo en la validación del captcha."— no further login processing occurs.
Local development
For local development, use Cloudflare’s official test keys. These always pass verification without contacting Cloudflare’s servers:.env
These test keys are provided by Cloudflare for development and CI use. Do not use them in production.
Key reference
| Variable | Visibility | Purpose |
|---|---|---|
NUXT_PUBLIC_TURNSTILE_SITE_KEY | Public (browser) | Renders the Turnstile widget in the login form. |
TURNSTILE_SECRET_KEY | Server only | Verifies the CAPTCHA token submitted with each login request. |