React Next JS Firebase onAuthStateChanged 不是函数

问题描述 投票:0回答:1

我有另一个页面,可以在其中注册帐户并将页面重定向到此页面,但出现以下错误: TypeError: (0 , firebase_util__WEBPACK_IMPORTED_MODULE_1_.getModularInstance)(...).onAuthStateChanged 不是一个函数

我使用的是 firebase 版本 11.0.1,并且遵循了 firebase 文档

'use client'
import Image from "next/image";
import styles from "./page.module.css";
import Dashboard from "./DashBoard/page";
import LoginPage from './auth/LoginPage/page';
import auth from './firebaseConfig'
import {onAuthStateChanged } from 'firebase/auth'
import { useEffect, useState } from "react";

export default function Home() {

  const [isAuthed,setIsAuthed] = useState(false);

  useEffect(() => {
    onAuthStateChanged(auth, (user) => {
      if(user){
        setIsAuthed(true);
      }
    })
  }, [])


  return (
    <div>
      {isAuthed?(<Dashboard/>):
      (<LoginPage/>)}
    </div>
  );
}

我尝试阅读文档,但它不适用于我的项目

reactjs firebase next.js firebase-authentication
1个回答
0
投票

我可以看看你的配置没有密钥吗?一定有 getAuth() 函数。

© www.soinside.com 2019 - 2024. All rights reserved.