簡體   English   中英

Firebase 谷歌登錄身份驗證和彈出窗口在 React 項目中不起作用

[英]Firebase google signin authentication and popup is not working in React project

實際上我不知道 firebase 只是遵循反應課程,我的講師使用相同的代碼但它在我這邊不起作用......我已經在 firebase 項目應用程序中啟用了谷歌登錄。 這是我導入 firebase、配置應用程序並使用 PopUp 方法的代碼

import firebase from "firebase/app";

import "firebase/auth";
import "firebase/firestore";

const config = {
  apiKey: "AIzaSyAl-E7TezE_hUH9QLXVegrG9w3X72tlBSs",
  authDomain: "crwn-db-65f80.firebaseapp.com",
  databaseURL: "https://crwn-db-65f80.firebaseio.com",
  projectId: "crwn-db-65f80",
  storageBucket: "crwn-db-65f80.appspot.com",
  messagingSenderId: "92304636614",
  appId: "1:92304636614:web:7cf30df27d77b20714f5c7",
  measurementId: "G-TN40FHGKV0"
};

firebase.initializeApp(config);

export const auth = firebase.auth();
export const firestore = firebase.firestore();

const provider = new firebase.auth.GoogleAuthProvider();
provider.setCustomParameters({ prompt: "select_account" });

export const signInWithGoogle = () => auth.signInWithGoogle(provider);

export default firebase;

這是來自另一個文件的一段代碼:

import {signInWithGoogle} from './firebase.utils';
<form onSubmit={this.handleSubmit}>
<button onClick={signInWithGoogle}>SignIn With Google </button>
</form>

如果我沒記錯的話,這是來自 Udemy 的 Complete React Developer in 2020(w/ Redux、Hooks、GraphQL)課程。

我也被困在這里然后我意識到我沒有在 CustomButton 組件中解壓自定義道具。 這樣做,讓我知道它是否有幫助:

const CustomButton = ({ children, ...props }) => {

如果您使用的是 Google Chrome 或 Microsoft Edge 瀏覽器,它會顯示為空白。 嘗試使用不同的瀏覽器(如 Firefox)。 這對我有用。

希望這可以幫助!

await GoogleSignin.revokeAccess();

await GoogleSignin.signOut();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM