我在 firebase.js 文件中配置 Firebase 持久性以保存在本地,以便我可以在整个应用程序中导出变量,但出现以下错误: FirebaseError: Firebase: Error (auth/already-initialized)., js 引擎:爱马仕
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { initializeAuth, getReactNativePersistence } from "firebase/auth";
import ReactNativeAsyncStorage from "@react-native-async-storage/async-storage";
export const firebaseConfig = {
apiKey: "ACHT5u4sf4",
authDomain: "eacom",
projectId: "ef",
storageBucket: "easom",
messagingSenderId: "93",
appId: "1:9600e56",
};
export const firebaseapp = initializeApp(firebaseConfig);
export const db = getFirestore(firebaseapp);
export const auth = initializeAuth(firebaseapp, {
persistence: getReactNativePersistence(ReactNativeAsyncStorage),
});
错误不断出现,因为您可能尝试使用通过initializeAuth 创建的“auth”。您不需要更改代码中的任何内容,只需添加以下内容: