An open API service indexing awesome lists of open source software.

https://github.com/halitsever/nest-cloudflare-turnstile

☁️ Cloudflare Turnstile Captcha integration for NestJS
https://github.com/halitsever/nest-cloudflare-turnstile

captcha cloudflare integration nest turnstile

Last synced: 24 days ago
JSON representation

☁️ Cloudflare Turnstile Captcha integration for NestJS

Awesome Lists containing this project

README

        



☁️ Cloudflare Turnstile integration for NestJS








Documentation



- 🧩 [**Simple and easy**](#) - This library provides just one guard to protect your endpoints with Cloudflare Turnstile Captcha!



Installation:

```bash
npm install nest-cloudflare-turnstile --save
```

add module to imports array with forRoot method:

```javascript

imports: [TurnstileModule.forRoot({
secretKey: '1x0000000000000000000000000000000AA',
tokenResponse: (req) => req.body.turnstileToken // or you can use req.headers.turnstileToken
})],

```

or with forRootAsync method:

```javascript
imports: [
TurnstileModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => {
const secretKey = config.get(
'CLOUDFLARE_TURNSTILE_PRIVATE_KEY',
);
if (!secretKey) {
throw new Error('Missing Cloudflare Turnstile secret');
}

return {
secretKey,
tokenResponse: (req) => req.body.turnstileToken,
};
},
}),
]
```

use `TurnstileCaptcha` decorator on controller:

```javascript

import { TurnstileCaptcha } from 'nest-cloudflare-turnstile'

@Post()
@TurnstileCaptcha()
getHello(): string {
return this.appService.getHello();
}
```

And thats it! For more information, please check the docs








MIT LICENSE | Halit Sever