--- title: Nuxt SDK description: "CaptchaLa Nuxt module: installation, module options, component, server utils, and verification flow." --- # Nuxt SDK Official Nuxt module for CaptchaLa CAPTCHA — published as [`@captcha-la/nuxt`](https://www.npmjs.com/package/@captcha-la/nuxt). Current version: **1.0.1**. - Auto-registers a client-only `` component (built on [`@captcha-la/vue`](./vue)) - Server utils `validateCaptchalaToken()` and `issueCaptchalaServerToken()`, auto-imported in your server routes - The app secret stays in the private runtime config and is never sent to the browser - Loads the web SDK from our CDN at runtime ## Install ```bash npm install @captcha-la/nuxt # or yarn add @captcha-la/nuxt # or pnpm add @captcha-la/nuxt ``` ```ts // nuxt.config.ts export default defineNuxtConfig({ modules: ['@captcha-la/nuxt'], captchala: { appKey: 'your-app-key' // public; or NUXT_PUBLIC_CAPTCHALA_APP_KEY } }) ``` ```bash # .env (server only) NUXT_CAPTCHALA_APP_SECRET=your-app-secret ``` ## Quick start ```vue ``` No import is needed. `app-key` defaults to the module's `appKey`; pass it to override. The component is client-only: on the server it renders an empty placeholder, and the SDK loads in the browser. ## Module options | Option | Type | Default | Description | |--------|------|---------|-------------| | `appKey` | `string` | `''` | Public app key: default `app-key` of the component, and the key for the server utils. Runtime override: `NUXT_PUBLIC_CAPTCHALA_APP_KEY` (component) / `NUXT_CAPTCHALA_APP_KEY` (server utils) | | `appSecret` | `string` | `''` | App secret for the server utils (private runtime config). Prefer `NUXT_CAPTCHALA_APP_SECRET` | | `componentName` | `string` | `'Captchala'` | Name of the auto-registered component | | `serverUtils` | `boolean` | `true` | Register the server utils | ## Props | Prop | Type | Default | Description | |------|------|---------|-------------| | `appKey` | `string` | module `appKey` | CaptchaLa application key | | `serverToken` | `string` | - | One-time, server-issued challenge token. Required when the app has `server_token_required=true`. See [`serverToken` mode](#server-token) | | `product` | `'popup' \| 'float' \| 'embed' \| 'bind'` | `'popup'` | Display mode | | `action` | `string` | `'default'` | Action identifier (e.g. `login`, `register`, `checkout`) | | `lang` | `string` | browser language | Language code (`zh-CN`, `en`, `ja`, …); unset = the browser language | | `theme` | `string \| object` | follows the system | Preset string or `{ custom: { brightness: 'light' \| 'dark' \| 'system', ... } }` (see [Web SDK options](../web-sdk#common-options)) | | `bindTo` | `string \| HTMLElement` | - | Element or selector to bind to (only for `product="bind"`) | | `onServerTokenExpired` | `() => Promise \| string \| null` | - | Called when `serverToken` is rejected; return a new token to retry once, or `null` | ## Events | Event | Payload | Description | |-------|---------|-------------| | `success` | `{ token, type, action }` | Verification succeeded | | `error` | `error` | Verification failed | | `close` | - | CAPTCHA closed | | `expired` | - | The pass token expired before it was used (once); with a listener, emitted instead of `error`; the widget shows the expiry. See [Token expiry](#token-expiry) | | `ready` | - | CAPTCHA ready | ## Methods (via `ref`) ```vue ``` | Method | Description | |--------|-------------| | `verify()` | Trigger verification | | `reset()` | Reset CAPTCHA state | | `destroy()` | Destroy the instance | | `bindTo(selector)` | Bind to element (for `bind` mode) | | `setLang(lang)` | Switch language in place | | `getInstance()` | The underlying web SDK instance | The ref is set once the component has mounted in the browser. ## Display modes ```vue ``` ## Server-side validation `validateCaptchalaToken(event, passToken, options?)` is auto-imported in `server/`. It calls `POST /v1/validate` with `pass_token` and `client_ip`, using the key and secret from the private runtime config: ```ts // server/api/login.post.ts export default defineEventHandler(async (event) => { const { email, password, captchaToken } = await readBody(event) // captchaToken = result.token from @success const captcha = await validateCaptchalaToken(event, captchaToken) if (!captcha.valid) { throw createError({ statusCode: 400, statusMessage: 'CAPTCHA verification failed' }) } // Token is valid, proceed with the request }) ``` Result: `{ valid, code, message?, data? }`. `valid` is `true` only when the API returned `code: 0` and `data.valid: true`; a missing token, network error or refusal gives `valid: false` (fail closed). Options: | Option | Type | Default | Description | |--------|------|---------|-------------| | `clientIp` | `string \| false` | request IP | The end user's IP; `false` omits it | | `xForwardedFor` | `boolean` | `false` | Read the IP from `X-Forwarded-For`. Enable only behind a proxy that sets it | For CI or local development you can use the public [test keys](/testing) as `NUXT_CAPTCHALA_APP_KEY` / `NUXT_CAPTCHALA_APP_SECRET` to exercise this path without solving a CAPTCHA. ## Production: `serverToken` mode {#server-token} For high-value flows (login, register, payment) we recommend the **server-issued token flow**. Your server mints a one-time `server_token` (5-minute TTL) with `POST /v1/server/challenge/issue` and the browser renders the widget with it. `issueCaptchalaServerToken(event, { action, ttl })` does the call: ```ts // server/api/captcha-token.get.ts export default defineEventHandler(async (event) => ({ server_token: await issueCaptchalaServerToken(event, { action: 'login' }) })) ``` ```vue ``` - The module keeps the app secret in the private runtime config; never embed it in browser code. - Each `server_token` can be used exactly once. Fetch a new one before every widget mount. - Apps with `server_token_required=false` can still use the public `appKey`-only flow. See [API Reference](/api-reference) for the full backend contract. ## Token expiry {#token-expiry} If the pass token runs out before the form uses it, the widget shows that the verification expired (in `bind` mode nothing is shown, since the button is yours) and `@expired` fires once, instead of `@error`. Start a new verification with `reset()` then `verify()` on the ref, or show your own prompt. ```vue ``` Without an `@expired` listener, `@error` fires once (class `expired`). `@expired` never fires for offline or degraded tokens. ## TypeScript The module options are typed (`captchala` key in `nuxt.config.ts`), and the server utils are typed when auto-imported. Component types come from `@captcha-la/vue`: ```ts import type { CaptchalaProps, CaptchalaResult } from '@captcha-la/vue' ``` ## Versions - **1.0.1** (2026-11-27): README in Japanese, Korean, Spanish, Portuguese (BR) and German; the server utils always call the CaptchaLa API endpoint. - **1.0.0**: first public release. ## Links - [npm](https://www.npmjs.com/package/@captcha-la/nuxt) · [GitHub](https://github.com/Captcha-La/nuxt) - [Vue SDK](./vue) · [Web SDK overview](/web-sdk) · [API Reference](/api-reference)