Skip to content Skip to sidebar Skip to footer

React - Firebase - GoogleAuthProvider Is Not A Constructor

I am trying to create a React application that uses a 'Login with Google' button to trigger signInWithPopup(provider). However each time I call new firebaseApp.auth.GoogleAuthProvi

Solution 1:

You're mixing namespaces with instance: the firebaseApp is just a container for configuration data. It is not how you create a provider instance.

The proper way is:

var provider = new firebase.auth.GoogleAuthProvider();

Solution 2:

I ran into this "not a constructor" problem and some other errors as well. I was doing something like this:

var googleProvider = new myApp.auth.GoogleAuthProvider();

When it should have been

var googleProvider = new firebase.auth.GoogleAuthProvider();

I was also initializing my app with a name like this:

var myApp = firebase.initializeApp(appConfig, "App");

Which didn't initialize a DEFAULT app & gave me more errors. I should have done this (since I only have one app)

var myApp = firebase.initializeApp(appConfig);

Solution 3:

I ran into this issue as I was trying to store a reference to firebase.auth to use in multiple functions.

I found that the GoogleAuthProvider function is a property of the auth firebase function whereas the signInWithPopup, onAuthStateChanged, signOut, etc. are on the firebase.auth.Auth returned by the firebase.auth() function.

This is what my code now looks like.

    //constructor
    this.auth = firebase.auth;
    this.auth_ = firebase.auth();
    ...
    //sign in function
    var provider = new this.auth.GoogleAuthProvider();
    this.auth_.signInWithPopup(provider); 

The sample code at https://codelabs.developers.google.com/codelabs/firebase-web/#5 is correct but this is a hard to notice difference when you paste this code in your solution and start messing with it.


Solution 4:

I also faced the same issue and now fortunately is working!

put this in firebase.js

export const provider = new firebase.auth.GoogleAuthProvider();

and import in login.js

import {firebaseApp,provider} from '../../../services/firebase_setup';


Solution 5:

Hi in your login.js modify the firebase import

try replace this:

import firebaseApp from '../../../services/firebase_setup';

for this:

import firebaseApp from "firebase/app";

I hope that solve the problem. Have a nice day!


Post a Comment for "React - Firebase - GoogleAuthProvider Is Not A Constructor"