【发布时间】:2021-11-14 10:54:47
【问题描述】:
我正在尝试使用 Firebase 为我的 React webapp 设置用户身份验证,但我在使用 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 新手。谁能帮忙解决这个错误?
【问题讨论】:
标签: javascript node.js reactjs firebase error-handling