【发布时间】:2021-12-17 06:47:11
【问题描述】:
我是 Next.js 开发的新手。我按照 Youtube 教程构建了一个 Whatsapp 克隆。 我使用firebase8.9作为数据库
我想检查用户是否登录,然后转到主页,否则重定向到登录页面。
import '../styles/globals.css'
import { useAuthState } from "react-firebase-hooks/auth"
import { auth, db } from "../firebase"
import Login from "./login"
function MyApp({ Component, pageProps }) {
const [user] = useAuthState(auth);
return <Component {...pageProps} />;
}
export default MyApp
我的 firebase.js 文件
import firebase from 'firebase';
const firebaseConfig = {
apiKey: "apikey",
authDomain: "authdomain",
projectId: "projectid",
storageBucket: "storagebucket",
messagingSenderId: "messagingsenderid",
appId: "appid"
};
const app = !firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app();
const db = app.firestore();
const auth = app.auth();
const provider = new firebase.auth.GoogleAuthProvider();
export { db, auth, provider };
请帮我解决这个问题。 提前致谢!
【问题讨论】:
标签: javascript firebase next.js typeerror