Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error thrown from executeAsync() and onErrored event #283

Open
roland-cromwell opened this issue Dec 14, 2023 · 2 comments
Open

Error thrown from executeAsync() and onErrored event #283

roland-cromwell opened this issue Dec 14, 2023 · 2 comments

Comments

@roland-cromwell
Copy link

roland-cromwell commented Dec 14, 2023

  • react-google-recaptcha version: 3.1.0
  • react-async-script version: n/a
  • react: 17.0.2
  • next.js: 12.2.5
  • formik: 2.29
  • yup: 0.29.3

Can someone tell me if the problem I have is due to me not having react-async-script installed in my application? Is this a dependency I'll need to install? It's not mentioned anywhere in the docs as far as I know.

Any help with this problem would be great.

I have checked thoroughly to make sure my API key has been configured and implemented correctly

  1. When a user clicks the Next button the code below runs and an error is thrown. The error being logged is undefined though.
const _recaptchaRef = useRef(null);

const handleNext = async () => {
    let reCaptchaToken;
    try {
      reCaptchaToken = await _recaptchaRef.current.executeAsync();
    } catch (error) {
      // error gets thrown here
      console.log('handleNextAction > reCaptcha error:', error);
    }
    if (reCaptchaToken) {
      // execute code
    } else {
      if (_recaptchaRef.current) {
        _recaptchaRef.current.reset();
      }
    }
  };
  1. The onErrored event is firing continuously and just logging an empty array.
<ReCAPTCHA
  ref={_recaptchaRef}
  sitekey={RECAPTCHA_KEY}
  size="invisible"
  badge="inline"
  hl="en-gb"
  asyncScriptOnLoad={(value) => {
    console.log('reCaptcha asyncScriptOnLoad:', value);
  }}
  onErrored={(...errorArgs) => {
    if (_recaptchaRef.current) {
      console.log(
        'reCaptcha onErrored args:',
        errorArgs
      );
      _recaptchaRef.current.reset();
    }
  }}
  onExpired={() => {
    if (_recaptchaRef.current) {
      console.log('reCaptcha onExpired');
      _recaptchaRef.current.reset();
    }
  }}
/>
@roland-cromwell
Copy link
Author

Closing this issue as the error was being caused by missing config on AWS which was blocking the API key.

@roland-cromwell
Copy link
Author

Closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant