Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firebase UI无法与google登录一起使用:updateCurrentUser失败_Javascript_Reactjs_Firebase_Firebase Authentication_Firebaseui - Fatal编程技术网

Javascript Firebase UI无法与google登录一起使用:updateCurrentUser失败

Javascript Firebase UI无法与google登录一起使用:updateCurrentUser失败,javascript,reactjs,firebase,firebase-authentication,firebaseui,Javascript,Reactjs,Firebase,Firebase Authentication,Firebaseui,我正在将FirebaseUI添加到我的react网站,基本代码来自本地州的github repo: . 当我尝试连接到firebase时,弹出窗口会显示我的google帐户。除非窗口取消显示,否则我的应用程序无法连接到我的google帐户并显示此信息。 我的代码是: import React from 'react'; import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth'; import firebase fr

我正在将FirebaseUI添加到我的react网站,基本代码来自本地州的github repo: . 当我尝试连接到firebase时,弹出窗口会显示我的google帐户。除非窗口取消显示,否则我的应用程序无法连接到我的google帐户并显示此信息。

我的代码是:

import React from 'react';
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth';
import firebase from 'firebase';
import { config } from '../../Components/Firebase/firebase';

firebase.initializeApp(config)

class Orders extends React.Component {

  // The component's Local state.
  state = {
    isSignedIn: false // Local signed-in state.
  };

  // Configure FirebaseUI.
  uiConfig = {
    // Popup signin flow rather than redirect flow.
    signInFlow: 'popup',
    // We will display Google and Facebook as auth providers.
    signInOptions: [
      firebase.auth.GoogleAuthProvider.PROVIDER_ID,
      firebase.auth.FacebookAuthProvider.PROVIDER_ID
    ],
    callbacks: {
      // Avoid redirects after sign-in.
      signInSuccessWithAuthResult: () => false
    }
  };

  // Listen to the Firebase Auth state and set the local state.
  componentDidMount() {
    this.unregisterAuthObserver = firebase.auth().onAuthStateChanged(
        (user) => this.setState({isSignedIn: !!user})
    );
  }
  
  // Make sure we un-register Firebase observers when the component unmounts.
  componentWillUnmount() {
    this.unregisterAuthObserver();
  }

  render() {
    if (!this.state.isSignedIn) {
      return (
        <div>
          <h1>My App</h1>
          <p>Please sign-in:</p>
          <StyledFirebaseAuth uiConfig={this.uiConfig} firebaseAuth={firebase.auth()}/>
        </div>
      );
    }
    return (
      <div>
        <h1>My App</h1>
        <p>Welcome {firebase.auth().currentUser.displayName}! You are now signed-in!</p>
        <a onClick={() => firebase.auth().signOut()}>Sign-out</a>
      </div>
    );
  }
}
从“React”导入React;
从“react firebaseui/StyledFirebaseAuth”导入StyledFirebaseAuth;
从“firebase”导入firebase;
从“../../Components/Firebase/Firebase”导入{config};
firebase.initializeApp(配置)
类命令扩展了React.Component{
//组件的本地状态。
状态={
isSignedIn:false//本地已登录状态。
};
//配置FirebaseUI。
uiConfig={
//弹出签名流,而不是重定向流。
signInFlow:“弹出窗口”,
//我们将显示谷歌和Facebook作为身份验证提供商。
签署:[
firebase.auth.GoogleAuthProvider.PROVIDER\u ID,
firebase.auth.FacebookAuthProvider.PROVIDER\u ID
],
回调:{
//避免在登录后重定向。
SignInsessWithAuthResult:()=>false
}
};
//收听Firebase身份验证状态并设置本地状态。
componentDidMount(){
this.unregisterAuthObserver=firebase.auth().onAuthStateChanged(
(user)=>this.setState({isSignedIn:!!user})
);
}
//确保在组件卸载时取消注册Firebase观察员。
组件将卸载(){
这是。取消注册AuthObserver();
}
render(){
如果(!this.state.isSignedIn){
返回(
我的应用程序
请登录:

); } 返回( 我的应用程序 欢迎{firebase.auth().currentUser.displayName}!您现在已登录

firebase.auth().signOut()}>注销 ); } }
你知道是什么原因吗?
谢谢

你能发布与身份验证相关的代码吗?是的,我刚刚发布了错误消息。错误消息是抱怨调用了updateCurrentUser,但你的代码没有显示这样的调用。请编辑该问题,以明确哪一行代码导致了错误。这是firebaseui的github为react提供的模板代码。在github中也没有提到这个电话……嘿@pledesch。看起来firebaseui web实际上依赖于firebaseui web。我发现此github问题:。这里有一些来自其他开发人员的建议,您可以尝试一下。总之,这似乎与加载sdk两次有关。可能一次通过npm,另一次通过脚本标记。删除一个可能有助于解决问题。希望这有帮助。