Home  >  Q&A  >  body text

Issue with reCAPTCHA callback in Firebase Phone Authentication

I'm trying to implement phone verification in my NextJS website, and I've added the reCAPTCHA code in my useEffect, but it's not getting triggered when the button with that id is clicked. There are no errors either. Here is the reCAPTCHA code:

window.recaptchaVerifier = new RecaptchaVerifier('btnPersonalInfoSubmit', {
                    'size': 'invisible',
                    'callback': (response) => {
                        console.log(response);
                      handlePersonalInfoUpdate();
                    },
                    'expired-callback': () => {
                        console.log('expired');
                    },
                    'error-callback': (error) => {
                        console.log(error);
                    }
                }, auth);

No output. Is there any reason?

P粉681400307P粉681400307205 days ago336

reply all(1)I'll reply

  • P粉720716934

    P粉7207169342024-03-29 11:41:37

    I figured it out.

    I had to add window.recaptchaVerifier.render() at the end. Final code:

    if (!window.recaptchaVerifier) {
                        window.recaptchaVerifier = new RecaptchaVerifier('btnPersonalInfoSubmit', {
                            'size': 'invisible',
                            'callback': (response) => {
                                handlePersonalInfoUpdate();
                            },
                            'expired-callback': () => {
                                console.log('expired');
                            },
                            'error-callback': (error) => {
                                console.log(error);
                            }
                        }, auth);
                        window.recaptchaVerifier.render()
                    }

    reply
    0
  • Cancelreply