skip to Main Content

I am using firebase to generate otp and i am getting an error about appVerificationDisabledForTesting being undefined.

recaptcha_verifier.ts:114 Uncaught TypeError: Cannot read properties of undefined (reading 'appVerificationDisabledForTesting')
    at new RecaptchaVerifier (recaptcha_verifier.ts:114:1)
    at generateRecaptcha (Home.js:123:1)
    at handleSend (Home.js:139:1)

here is the code i am using

const handleSend = (event) => {
    event.preventDefault();

    generateRecaptcha();
    let appVerifier = window.recaptchaVerifier;
    signInWithPhoneNumber(auth, phoneNumber, appVerifier)
      .then((confirmationResult) => {
        // SMS sent. Prompt user to type the code from the message, then sign the
        // user in with confirmationResult.confirm(code).
        window.confirmationResult = confirmationResult;
      })
      .catch((error) => {
        // Error; SMS not sent
        console.log(error);
      });
  };

the error is coming from generateRecaptcha();

const generateRecaptcha = () => {
    window.recaptchaVerifier = new RecaptchaVerifier(
      "recaptcha",
      {
        size: "invisible",
        callback: (response) => {
          // reCAPTCHA solved, allow signInWithPhoneNumber.
          // ...
        },
      },
      auth
    );
  };

2

Answers


  1. "firebase": "^9.4.1"

    change the firebase version to 9.4.1 and it will work i too got stuck with this error and have been searching for the solution this is the only solution i got for now

    Login or Signup to reply.
  2. Just change the arrangement on initiating RecaptchaVerifier, like this:

    Firebase < 9:
    new RecaptchaVerifier('recaptcha-container', {}, auth);

    Firebase > 10:
    new RecaptchaVerifier(auth, 'recaptcha-container', {});

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search