简体   繁体   English

Firebase Google 身份验证构造函数未定义错误

[英]Firebase Google Authentication Constructor undefined Error

Soo.苏。 I have been trying to implement Firebase google auth in my project, Unfortunately I ran into the following error on the console我一直在尝试在我的项目中实现 Firebase google auth,不幸的是我在控制台上遇到了以下错误

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'constructor')
    at _assertInstanceOf (assert.ts:101:1)
    at signInWithPopup (popup.ts:86:1)
    at signInWithGoogle (App.js:52:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
    at invokeGuardedCallback (react-dom.development.js:4277:1)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1)
    at executeDispatch (react-dom.development.js:9041:1)
    at processDispatchQueueItemsInOrder (react-dom.development.js:9073:1)
    at processDispatchQueue (react-dom.development.js:9086:1) 

The Code goes as followed代码如下

import React from "react";
import { initializeApp } from "firebase/app";
import { getAuth , GoogleAuthProvider , signInWithPopup } from "firebase/auth"

const app = initializeApp(firebaseConfig);

const auth = getAuth(app);

function Home() {
    const [user] = useAuthState(auth);
    return (
        <div className="App">
            <header>Welcome to PixShare</header>
            <h1>
                Home
                <section>
                    {user ? <Home /> : <SignIn />}
                </section>
            </h1>
        </div>
    );
}

const SignIn = () => {
    const signInWithGoogle = () => {
        const provider = new GoogleAuthProvider();
        signInWithPopup(provider)
    }

    return (
        <button onClick={ signInWithGoogle }>
            Sign In With Google
        </button>
    );
};

export default Home;

Can someone help me with what went wrong?有人可以帮我解决问题吗? The package.json file is as shown below package.json文件如下图

{
  "name": "pixshare",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^13.5.0",
    "firebase": "^9.9.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-firebase-hooks": "^5.0.3",
    "react-router-dom": "^6.3.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Does anyone know where I went wrong?有谁知道我哪里出错了? Could really use some help真的可以使用一些帮助

The signInWithPopup() function takes an Auth instance as the first argument. signInWithPopup() function 将Auth实例作为第一个参数。
So the signInWithPopup(provider) function should be signInWithPopup(auth, provider)所以signInWithPopup(provider) function 应该是signInWithPopup(auth, provider)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 谷歌身份验证错误 - Firebase error with Google Authentication Firebase 身份验证错误:未定义名称'auth' - Firebase authentication error: Undefined name 'auth' Firebase 使用 React 进行谷歌身份验证 - Firebase Google Authentication with React Chrome 扩展程序中的 Firebase 谷歌身份验证 - 获取凭据时出错 - Firebase google authentication in Chrome Extension - Error getting credential 使用 Firebase 和 Jetpack Compose 进行谷歌身份验证 - Google authentication with Firebase and Jetpack Compose Google Firebase 错误(函数返回未定义,预期为 Promise 或值) - Google Firebase Error(Function returned undefined, expected Promise or value) Firebase 使用谷歌身份验证 (GoogleYOLO) - Firebase Authentication with Google Identity (GoogleYOLO) Firebase 使用 email 和 google 进行身份验证 - Firebase Authentication using email and google 尝试为 Firebase 身份验证启用 Google 登录时出现“更新 Google 时出错”消息 - "Error updating Google" message when trying to enable Google Sign-In for Firebase Authentication 类型错误:无法读取未定义的属性(读取“创建”)Firebase 身份验证登录错误 - TypeError: Cannot read properties of undefined (reading 'create') Firebase authentication sigin error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM