question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

new firebase.auth.RecaptchaVerifier does not work

See original GitHub issue

Version

@nuxtjs/firebase: 6.1.1 firebase: 7.21.1 nuxt: 2.14.5

Trying to use the phone auth and it requires us to use the Firebase recaptcha, as per the official docs, we are to use the below syntax to initialise the Recaptcha Verifier.

window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('sign-in-button', {
  'size': 'invisible',
  'callback': function(response) {
    // reCAPTCHA solved, allow signInWithPhoneNumber.
    onSignInSubmit();
  }
});

Steps to reproduce

  1. Use the Nuxt Firebase’s Authentication shortcut to initialise the above method
<script>
export default {
  mounted() {
    window.recaptchaVerifier = new this.$fireAuth.RecaptchaVerifier(
      "sign-in-button",
      {
        size: "invisible",
        callback: function (response) {
          // reCAPTCHA solved, allow signInWithPhoneNumber.
          onSignInSubmit();
        },
      }
    );
  },
};
</script>

What is Expected?

Recaptcha is verified

What is actually happening?

Throws a Nuxt error this.$fireAuth.RecaptchaVerifier is not a constructor

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
jhonyjsscommented, Apr 16, 2021

This worked for me !

<button type="submit" class="btn btn-primary" id="recaptcha-container">LOGIN</button>
 mounted () {
      this.appVerifier = new this.$fireModule.auth.RecaptchaVerifier('recaptcha-container', {
        'size': 'invisible',
        'callback': (response) => {
          console.log('workrs')
          // reCAPTCHA solved, allow signInWithPhoneNumber.
          // onSignInSubmit();
        }
      });
    },
  
  methods: {
    async login () {
      const loginWithNumber = await this.$fire.auth.signInWithPhoneNumber('+5511999999999',this.appVerifier)
      console.log(loginWithNumber)
    }
  },
0reactions
srijaydeathwishcommented, Jun 22, 2022

@fayazara this.$fireAuth is the Firebase Auth instance, what you need to access RecaptchaVerifier is the module, like so this.$fireAuthObj.RecaptchaVerifier.

See https://firebase.nuxtjs.org/guide/usage#general-usage

If you closely look at the official docs there is a difference between auth().something and auth.something - this is what the difference between $fireAuthObj and $fireAuth is.

Let me know if that helped.

Thanks to @fayazara, I figured out what I was doing wrong as well. If anyone is using @nuxtjs/firebase module, to use recaptcha you need to do “this.$fireModule.auth.RecaptchaVerifier” and for signinWithPhoneNumber it is “this.$fire.auth.signInWithPhoneNumber”.

$fireModule being the keyword for Recaptcha.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase Phone Auth Recaptcha Verifier not being set to ...
I managed to fix it. I moved the 'new' statement into my context provider: // In context.js recaptchaVerifier = (container, ...
Read more >
RecaptchaVerifier | Firebase JavaScript API reference
Reference for RecaptchaVerifier. ... Firebase Auth backend provisions a reCAPTCHA for each project and will configure this upon rendering.
Read more >
Notes - Full-Stack Firebase
Firebase Authentication. See the Firebase Authentication docs for web. ... No user is signed in. ... recaptchaVerifier = new firebase.auth.
Read more >
FirebaseRecaptcha
Firebase phone authentication is not possible out of the box using the Firebase JS SDK. This because an Application Verifier object (reCAPTCHA) is...
Read more >
Firebase Phone Authentication in Ionic 5 Apps
Step 5— Phone auth without ReCaptcha. In this step, developers have two options to make the Phone authentication flow work :-. Do not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found