JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 24
  • Score
    100M100P100Q67125F
  • License MIT

A library for integrating and working with Cloudflare CAPTCHA in NestJS applications.

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nestjs-cloudflare-captcha) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    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:

    npm install nestjs-cloudflare-captcha
    # or
    yarn add nestjs-cloudflare-captcha

    Usage

    1. Module Configuration

    To use CloudflareCaptchaModule, you need to import it into your main module and pass the configuration.

    Example using synchronous configuration:

    import { Module } from '@nestjs/common'
    import { CloudflareCaptchaModule } from 'nestjs-cloudflare-captcha'
    
    @Module({
        imports: [
            CloudflareCaptchaModule.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:

    import { Module } from '@nestjs/common'
    import { CloudflareCaptchaModule } from 'nestjs-cloudflare-captcha'
    
    @Module({
        imports: [
            CloudflareCaptchaModule.forRootAsync({
                useFactory: async (configService: ConfigService) => ({
                    secretKey: configService.get('CAPTCHA_SECRET_KEY'),
                    token: req => req.body.captchaToken,
                    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:

    import { Controller, Post } from '@nestjs/common'
    import { Turnstile } from 'nestjs-cloudflare-captcha'
    
    @Controller('auth')
    export class SomeController {
        @Post('login')
        @Turnstile()
        login() {
            return 'This method is protected from bots with CAPTCHA'
        }
    }

    Support

    If you have any questions or issues, feel free to contact the author.

    License

    This project is licensed under the MIT License.