@seccom/cf-turnstile
v1.0.10
Published
Simple server side implementation of Cloudflare Turnstile captcha.
Downloads
4
Readme
Simple Turnstile serverside validator
Simple server side implementation of Cloudflare Turnstile captcha.
How to use packages server side validation:
import {Turnstile} from '@seccom/turnstile'
const SECRET_KEY = '1x0000000000000000000000000000000AA';
...
const cfTurnstileResponse = req.body["cf-turnstile-response"]
const remoteip = req.headers['CF-Connecting-IP'] || req.headers['x-forwarded-for'] || req.socket.remoteAddress
const turnstile = new Turnstile({token: SECRET_KEY})
const turnstileResponse = await turnstile.validate({remoteip, response: cfTurnstileResponse})
if(!turnstileAnswer.valid) {
....handle invalid captcha
}
...
turnstileResponse object:
{
valid: boolean, => Indicates if capcha solved correctly?
messages: string[] => In case of an error the messages from cloudflare are passed here.
}
Client side implementaion For client side implementaion see official documentation or use other npm package suitable for your framework.