我尝试在我的React.JS应用程序上实现Firebase进行身份验证。但是,我一直收到此错误
8:00 -32请检查您的浏览器是否存在错误。
找不到模块:错误:包路径.未从包/Users/Aarnav/Desktop/JavaScript/my-app copy 2/node_modules/firebase中导出(请参阅/Users/Aarnav/Desktop/JavaScript/my-app copy 2/node_modules/firebase/package.json中的导出字段)
我的Firebase设置如下所示,
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
const firebaseConfig = {
apiKey: "AIzaSyCPSbjZ9F1TgI43T0SH68rUi9TMHBXRw - s",
authDomain: "csia-41409.firebaseapp.com",
databaseURL: "https://csia-41409-default-rtdb.firebaseio.com",
projectId: "csia-41409",
storageBucket: "csia-41409.appspot.com",
messagingSenderId: "714268776254",
appId: "1:714268776254:web:93d9ef26a5d9c7d7f8be6f",
};
const app = initializeApp(firebaseConfig);
export const auth = getAuth();
我的身份上下文看起来
import React, { useContext, useState, useEffect } from "react"
import { auth } from "firebase";
const AuthContext = React.createContext();
export function useAuth() {
return useContext(AuthContext);
}
export function AuthProvider({ children }) {
const [currentUser, setCurrentUser] = useState();
const [loading, setLoading] = useState(true);
function signup(email, password) {
return auth.createUserWithEmailAndPassword(email, password);
}
function login(email, password) {
return auth.signInWithEmailAndPassword(email, password);
}
useEffect(() => {
const unsubscribe = auth.onAuthStateChanged((user) => {
setCurrentUser(user);
setLoading(false);
});
return unsubscribe;
}, []);
auth.onAuthStateChanged((user) => {
setCurrentUser(user);
});
const value = {
currentUser,
login,
signup,
};
return (
<AuthContext.Provider value={value}>
{!loading && children}
</AuthContext.Provider>
);
}
也由于某种原因,我的整个网站是一个空白的白色屏幕,无论哪个路由器(页),我相信这是因为上面提到的错误,但我不确定。
起初我以为这是因为我使用的是Firebase版本9. 14,然而,我更新了Firebase的设置,但无济于事,错误仍然存在。我不知道如何删 debugging 误。
1条答案
按热度按时间9rygscc11#
在firebase V9中,你应该这样用email和密码注册和登录:
第一个