我试图为我的React webapp设置Firebase用户身份验证,但我遇到了firebaseAuth.app()函数的错误。我尝试在项目目录中重新安装firebase和firebase admin,将导入转换为SDK 9语法,并重新排序某些语句,但似乎没有任何工作。这是我的App.js文件:
import withFirebaseAuth from 'react-with-firebase-auth'
import firebase from 'firebase/compat/app';
import 'firebase/auth';
import firebaseConfig from './firebaseConfig';
import "firebase/compat/app";
import "firebase/compat/analytics";
import { initializeApp } from 'firebase/app';
import { getAuth } from "firebase/auth";
const firebaseApp = firebase.initializeApp(firebaseConfig);
const firebaseAppAuth = firebaseApp.auth();
const providers = {
googleProvider: new firebase.auth.GoogleAuthProvider(),
};
const {
user,
signOut,
signInWithGoogle,
} = this.props;
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
{
user
? <p>Hello, {user.displayName}</p>
: <p>Please sign in.</p>
}
{
user
? <button onClick={signOut}>Sign out</button>
: <button onClick={signInWithGoogle}>Sign in with Google</button>
}
</header>
</div>
);
}
export default withFirebaseAuth({
providers,
firebaseAppAuth,
})(App);
我有一个firebaseConfig.js文件以及配置信息。很抱歉,因为我是React的新手。有人能帮忙解决这个错误吗?
尝试将所有导入更改为compat
版本:
import withFirebaseAuth from 'react-with-firebase-auth'
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import "firebase/compat/app";
import "firebase/compat/analytics";
import firebaseConfig from './firebaseConfig';
我建议检查并升级到新的模块化SDK,但我不完全确定它是否可以与'react-with-firebase-auth'
或任何其他库一起工作。