https://github.com/teacoder-team/nestjs-cloudflare-captcha
🌐 A library for integrating and working with Cloudflare CAPTCHA in NestJS applications. 🔐
https://github.com/teacoder-team/nestjs-cloudflare-captcha
captcha cloudflare library nestjs nestjs-library turnstile
Last synced: 6 months ago
JSON representation
🌐 A library for integrating and working with Cloudflare CAPTCHA in NestJS applications. 🔐
- Host: GitHub
- URL: https://github.com/teacoder-team/nestjs-cloudflare-captcha
- Owner: teacoder-team
- License: mit
- Created: 2024-12-17T05:57:56.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-12-21T02:54:59.000Z (10 months ago)
- Last Synced: 2025-03-23T15:17:42.952Z (7 months ago)
- Topics: captcha, cloudflare, library, nestjs, nestjs-library, turnstile
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/nestjs-cloudflare-captcha
- Size: 499 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NestJS Cloudflare CAPTCHA
This module provides integration with Cloudflare CAPTCHA (also known as Turnstile) for NestJS-based applications.
## Installation
To install this module, use npm or yarn:
```bash
npm install nestjs-cloudflare-captcha
# or
yarn add nestjs-cloudflare-captcha
```## Usage
### 1. Module Configuration
To use TurnstileModule, you need to import it into your main module and pass the configuration.
**Example using synchronous configuration:**
```typescript
import { Module } from '@nestjs/common'
import { TurnstileModule } from 'nestjs-cloudflare-captcha'@Module({
imports: [
TurnstileModule.forRoot({
secretKey: process.env.CAPTCHA_SECRET_KEY,
token: req => req.body.captchaToken,
skipIf: process.env.NODE_ENV === 'development',
}),
],
})
export class AppModule {}
```**Example using asynchronous configuration:**
```typescript
import { Module } from '@nestjs/common'
import { TurnstileModule } from 'nestjs-cloudflare-captcha'@Module({
imports: [
TurnstileModule.forRootAsync({
useFactory: async (configService: ConfigService) => ({
secretKey: configService.get('CAPTCHA_SECRET_KEY'),
token: req => req.headers['captcha-token'],
skipIf: configService.get('NODE_ENV') === 'development',
}),
}),
],
})
export class AppModule {}
```### 2. Protect Routes with CAPTCHA
To protect routes from bots, use Turnstile as a decorator.
**Example usage in a controller:**
```typescript
import { Controller, Post } from '@nestjs/common'
import { Turnstile } from 'nestjs-cloudflare-captcha'@Controller('auth')
export class AuthController {
@Post('login')
@Turnstile()
async login() {
return 'This method is protected from bots with CAPTCHA'
}
}
```## Support
If you have any questions or issues, feel free to contact the author.
- Author: [TeaCoder](https://teacoder.ru)
- Contributors:
- Vadim Nechaev (help@teacoder.ru)## License
This project is licensed under the [MIT License](LICENSE).