H-Captcha can't verify captcha key/token

1.4k Views Asked by At

Here is my code:

let result = await axios({
            method: 'post',
            url: 'https://hcaptcha.com/siteverify',
            params: {
                secret: "secret would be here",
                response: req.body.hcap
            }
        });
        let data = result.data || {};
        console.log(result)
        if(!data.success){
            res.send("bad token")
            return
        }
        else{
            res.send("good token") 
        }

I know that the token sent to the server is good.

Here is the error I'm receiving:

'error-codes': [ 'missing-input-response', 'missing-input-secret' ]
2

There are 2 best solutions below

0
On BEST ANSWER

I ended up finding the solution to be installing the hcaptcha package which made this a lot simpler.

0
On

You have to transfer your data to a URLSearchParams object. The following code works for me:

const res = await axios
    .post(
        "https://hcaptcha.com/siteverify",
        new URLSearchParams({
            secret: process.env.HCAPTCHA_SECRET ?? "",
            response: verificationToken
        })
    )
    .then(res => res.data);