skip to Main Content

why do i face this error when sending otp with firebase

these are codes

import { RecaptchaVerifier, getAuth, signInWithPhoneNumber} from 'firebase/auth'; import { initializeApp } from 'firebase/app'

sendCode() { 
    window.appVerifier = new RecaptchaVerifier(
      "recaptcha-container",
      {
        size: "invisible",
      }
      , getAuth()
    );
    const appVerifier = window.appVerifier;
    this.setState({
      mobile: this.props.mobile,
      disabled: false,
    });
    var number = "+65 " + this.props.mobile;
    console.log(number);
    signInWithPhoneNumber(getAuth(), number, appVerifier)
      .then(function (confirmationResult) {
        console.log("Success");
        // SMS sent. Prompt user to type the code from the message, then sign the
        // user in with confirmationResult.confirm(code).
        window.confirmationResult = confirmationResult;
        this.setState({confirmResult: confirmationResult});
        console.log(confirmationResult);
componentDidMount() {
    initializeApp(firebaseConfig);
  }
   <div id="recaptcha-container" />

i keep receiving this error
enter image description here

anybody can let me know where im doing wrong please ?

Thank you!

2

Answers


  1. Chosen as BEST ANSWER
    sendCode() {
        this.setState({
          mobile: this.state.mobile,
          disabled: false,
        });
        var number = "+65 " + this.state.mobile;
        console.log(number);
    
        window.recaptchaVerifier = new RecaptchaVerifier(getAuth(), "recaptcha-container", {
          'size': 'invisible'
        });
        const appVerifier = window.recaptchaVerifier;
    
        signInWithPhoneNumber(getAuth(), number, appVerifier)
        .then(function (confirmationResult) {
          console.log("Success");
          window.confirmationResult = confirmationResult;
          console.log(confirmationResult);
    

  2. maybe this would help,

    import { getAuth, RecaptchaVerifier } from "firebase/auth";
    
    const auth = getAuth();
    window.recaptchaVerifier = new RecaptchaVerifier(auth, 'recaptcha-container', 
    {
      'size': 'normal',
    });
    

    according to firebase docs first parameter is Auth then containerOrId then RecaptchaParameters

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