Reputation: 48
Im trying to add captcha to my react app and the front end works just fine as expected. but when the backend calls the api to verify the captcha response (api) i get the following response { success: false, 'error-codes': [ 'missing-input-secret' ] }
.
Now when i log the request to see what data is being sent. i get this image. as you can see the secret and response is being sent and my headers are correct but for some reason im getting an error.
heres my code:
const captchaRequest = await axios.post('https://www.google.com/recaptcha/api/siteverify', {
secret: config.captchaSecretKey,
response: captcha
}, {
headers: {
'Content-Type': 'application/json',
}
});
const captchaResponse = captchaRequest.data;
if (!captchaResponse.success) {
return res.status(401).json({
message: 'captcha failed',
success: false,
});
}
If someone could please let me know what im doing wrong let me know.
Upvotes: 1
Views: 1804
Reputation: 36
Had the same problem. you have to send the data as parameters and not in the body.
const captchaResponse = await axios({
method: 'post',
url: 'https://www.google.com/recaptcha/api/siteverify',
params: {
secret: SECRET,
response: CAPTCHA_RESPONSE
}
});
Upvotes: 2