Skip to main content

Guards

Guard list

GuardDescription
CaptchaGuardProtects HTTP routes by validating a captcha token using the active provider.

How it works

  • Reads the captcha token from headers (default) or body
  • Uses CaptchaService.verifyAsync(token) to validate
  • Throws UnauthorizedException if the token is missing or invalid

Usage

example.controller.ts
import { Controller, Post, UseGuards } from '@nestjs/common';
import { CaptchaGuard } from 'nestjs-captcha-module';

@Controller('example')
export class ExampleController {
@Post('submit')
@UseGuards(CaptchaGuard)
submit() {
return { ok: true };
}
}
note

By default, the guard expects the token in the x-captcha-token header. You can customize this via guardOptions when registering the module.