'How to verify ReCAPTCHA token in js?
I have written the following function in js to verify a ReCAPTCHA token:
export async function validateHuman(token) {
const secret = "funny_little_secret";
const response = await fetch(
"https://www.google.com/recaptcha/api/siteverify?secret=" +
secret +
"&response=" +
token,
{ method: "POST" }
);
const data = response.json();
return data.success;
}
For reasons I do not understand, I get a fetch error while running this. I have looked in to a few other versions of the functions but have not yet found a solution.
Moreover, the token is correct and is produced according to the documentation, so I am wondering whether there is something wrong about my secret, as I have seen others use something along the lines of process.env.secret
, which I have tried without success, or it there is something I do not understand about the fetch function.
This is the complete error:
Uncaught TypeError: Failed to fetch
validateHuman @ http://localhost:3000/static/js/bundle.js:3384:26
thanks in advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|