Fix-Catch invalid google recaptcha v3 key error (#6034)

* Handle invalid google recaptcha v3 key
This commit is contained in:
Vicky Bansal 2021-08-09 17:48:58 +05:30 committed by GitHub
parent 22f30d09b0
commit a8871770c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -240,12 +240,7 @@ function RecaptchaV3Component(
) {
// Check if a string is a valid JSON string
const checkValidJson = (inputString: string): boolean => {
try {
JSON.parse(inputString);
return true;
} catch (err) {
return false;
}
return !inputString.includes('"');
};
const handleBtnClick = (event: React.MouseEvent<HTMLElement>) => {
@ -278,11 +273,9 @@ function RecaptchaV3Component(
};
let validGoogleRecaptchaKey = props.googleRecaptchaKey;
if (validGoogleRecaptchaKey && checkValidJson(validGoogleRecaptchaKey)) {
if (validGoogleRecaptchaKey && !checkValidJson(validGoogleRecaptchaKey)) {
validGoogleRecaptchaKey = undefined;
}
const status = useScript(
`https://www.google.com/recaptcha/api.js?render=${validGoogleRecaptchaKey}`,
);