I’m trying to implement ReCaptcha v3 API on www.frink.global and having a problem. I’ve managed to narrow it down to a fetch made from the backend that seems to be returning the wrong response. When I make a POST call to the exact same URL using Postman, I get back the correct JSON response.
Can you see something I’m doing? The error appears to be within this section of code.
Seems to be the fetch call in particular, like I said I’ve double checked and sent all the same info to the URL using postman and it works.
import { fetch } from 'wix-fetch';
const secret = "<insert ReCaptcha secret"
export function verify(token) {
const url = "https://www.google.com/recaptcha/api/siteverify";
var bodydata = JSON.stringify({
"secret": secret,
"response": token
});
var headerData = JSON.stringify({
"Accept": "*/*",
"Cache-Control": "no-cache",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive"
});
fetch(url, { method: "post",
headers:headerData,
body:bodydata })
.then((httpResponse) => {
var cache = [];
let httpResponseBodyStringified = JSON.stringify(httpResponse.body,
function(key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Duplicate reference found, discard key
return;
}
// Store value in our collection
cache.push(value);
}
return value;
});
if (httpResponse.ok) {
return httpResponse.json();
}
})
return "I didn't verify";
}
This might help:
https://www.wix.com/corvid/forum/community-discussion/how-to-set-up-recaptcha-v3-tutorial
Based my code off of this tutorial. Intentionally using POST instead of GET but have tried both. Tried sending as URL instead of body, both give same result as expected.
Thank you for your time!