auth.signInwithPopup 不是 firebase 的函数

use*_*003 6 javascript google-authentication firebase-authentication

我正在使用 firebase google 身份验证来使用 goole 对用户进行身份验证。

但我面临一个错误,如下所示......

(0, _auth.signInWithPopup) is not a function. (In '(0, _auth.signInWithPopup)(auth, provider)', '(0, _auth.signInWithPopup)' is 
undefined)
Run Code Online (Sandbox Code Playgroud)

并且无法修复它。

这是我的代码...

进口声明

import {getAuth,GoogleAuthProvider,signInWithPopup} from "firebase/auth"
Run Code Online (Sandbox Code Playgroud)

功能

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)
        }
        
    }
Run Code Online (Sandbox Code Playgroud)

请告诉我如何解决这个错误...

提前致谢

小智 -1

getAuth() 函数不能为空。首先,您应该将可在 firebase app -> 项目设置中找到的 firebase 配置传递给initializeApp() 函数。然后将结果传递给 getAuth() 函数。

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);
Run Code Online (Sandbox Code Playgroud)