auth.signInwithPopup is not a function firebase

Viewed 1446

I am using firebase google authentication to authenticate user using goole.

But i am facing an error which is given below....

(0, _auth.signInWithPopup) is not a function. (In '(0, _auth.signInWithPopup)(auth, provider)', '(0, _auth.signInWithPopup)' is 
undefined)

and unable to fix it.

here is my code ...

import statements

import {getAuth,GoogleAuthProvider,signInWithPopup} from "firebase/auth"

the function

const googlelogin=async()=>{
        const auth=getAuth()
        const provider=new  GoogleAuthProvider()
        try{
            
            const result=await signInWithPopup(auth,provider)
            // const credentials=GoogleAuthProvider.credentialFromResult(result);
            // const token=credentials.accessToken
            // const user=result.user
        }
        catch(e){
            console.log(e)
        }
        
    }

Please tell me how to solve this error...

Thanks in advance

1 Answers

getAuth() function can not be empty. first you should pass the firebase configurations which are can be found on firebase app -> project settings to the initializeApp() function. then pass the results to the getAuth() function.

import {initializeApp} from "firebase/app";
import {getAuth} from 'firebase/auth';

const firebaseConfig = {
  apiKey: "",
  authDomain: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: "",
  appId: ""
};

const firebaseApp = initializeApp(firebaseConfig);
const auth = getAuth(firebaseApp);
Related