I am currently dealing with the property success defined in the API (reCAPTCHA).
/**
* The structure of response from the veirfy API is
* {
* "success": true|false,
* "challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
* "hostname": string, // the hostname of the site where the reCAPTCHA was solved
* "error-codes": [...] // optional
}
*/
I attempted to use optional chaining below to solve this issue, but it proved unsuccessful. I also tried using an interface at different stages, but could not resolve the problem that way either.
Here is the code snippet:
import fetch from "node-fetch"
//...
try {
const response = await fetch(
`https://www.google.com/recaptcha/api/siteverify?secret=${process.env.GOOGLE_RECAPTCHA_SECRETKEY}&response=${captcha}`,
{
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
},
method: "POST",
}
);
const captchaValidation = await response.json();
if(captchaValidation?.success) // error: Property 'success' does not exist on type '{}'
} catch (error) {}
How can I access that property successfully?