@ccatto/nest-recaptcha
v1.0.0
Published
Catto reCAPTCHA - NestJS Google reCAPTCHA v3 verification
Downloads
50
Maintainers
Readme
@ccatto/nest-recaptcha
NestJS dynamic module for Google reCAPTCHA v3 server-side verification.
Install
npm install @ccatto/nest-recaptcha
# or
yarn add @ccatto/nest-recaptchaQuick Start
import { Module } from '@nestjs/common';
import { CattoRecaptchaModule } from '@ccatto/nest-recaptcha';
@Module({
imports: [
CattoRecaptchaModule.forRoot({
secretKey: process.env.RECAPTCHA_SECRET_KEY,
scoreThreshold: 0.5,
}),
],
})
export class AppModule {}Inject the service to verify tokens:
import { CattoRecaptchaService } from '@ccatto/nest-recaptcha';
@Injectable()
export class ContactService {
constructor(private readonly recaptcha: CattoRecaptchaService) {}
async handleSubmit(token: string) {
const result = await this.recaptcha.verify(token);
if (!result.success) throw new BadRequestException('reCAPTCHA failed');
}
}Peer Dependencies
| Package | Version | Required |
| --- | --- | --- |
| @nestjs/common | >=10.0.0 | Yes |
| @nestjs/core | >=10.0.0 | Yes |
| reflect-metadata | >=0.1.0 | Yes |
License
MIT
