FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

teacoder-team/nestjs-cloudflare-captcha: 🌐 A library for integrating and working with Cloudflare CAPTCHA in NestJS applications. 🔐 · GitHub

Latest commit

 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 TurnstileModule, you need to import it into your main module and pass the configuration.

Example using synchronous configuration:

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:

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:

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.

License

This project is licensed under the MIT License.

About

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

Topics

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages


Back | FazBrowse Home | New Git URL