@adscore/uncaptcha
v1.0.0
Published
A simple and free CAPTCHA solution easy to integrate and use by developers and non-developers alike.
Downloads
6
Readme
UnCaptcha Node Lib
A simple and free CAPTCHA solution easy to integrate and use by developers and non-developers alike.
How to install
Requires NodeJS >=8.0
npm i @adscore/uncaptcha
How to use
- Go to uncaptcha https://uncaptcha.com/
- Generate private and public seed.
- Follow instructions on https://uncaptcha.com/ to implement captcha in the frontend
- In NodeJs:
const { UnCaptchaService } = require("@adscore/uncaptcha");
try {
// UnCaptcha will add hidden input to the form with name 'uncaptcha-token'
const captcha = "<UNCAPTCHA_TOKEN_FROM_REQUEST>";
const visitorUserAgent = "<OPTIONAL_VISITOR_USER_AGENT>";
const visitorIp = "<OPTIONAL_VISITOR_IP>";
const unCaptchaService = new UnCaptchaService("<PRIVATE_SEED>");
await unCaptchaService.verify(captcha, visitorUserAgent, visitorIp);
} catch (error) {
/**
* Throws object:
* {
* statusCode: 400,
* message: "Invalid Request"
* }
*/
console.log(error);
}
Possible errors:
Request Failed
Something went wrong on our side, please create an issue in GitHub.
{
statusCode: 503,
message: "Request Failed"
}
Invalid Request
Something is wrong with the data, check if you sending captcha without additional characters and if visitor IP and User Agent are correct.
It is also possible that visitor is trying to forge the request, this error will be returned for this situation.
{
statusCode: 400,
message: "Invalid Request"
}
Expired Request
Captcha Expired, user need to use captcha again.
{
statusCode: 410,
message: "Expired Request"
}