| import { initializeApp } from "firebase/app"; |
| import { getAuth } from "firebase/auth"; |
| import { getFirestore, doc, getDocFromServer } from "firebase/firestore"; |
| import { getStorage } from "firebase/storage"; |
| import firebaseConfig from "../../firebase-applet-config.json"; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| const app = initializeApp(firebaseConfig); |
|
|
| |
| export const db = getFirestore(app, firebaseConfig.firestoreDatabaseId); |
| export const auth = getAuth(app); |
| export const storage = getStorage(app); |
|
|
| |
| export async function testConnection() { |
| try { |
| await getDocFromServer(doc(db, "test", "connection")); |
| console.log("Firebase Connection verified successfully."); |
| } catch (error) { |
| if (error instanceof Error && error.message.includes("offline")) { |
| console.error("Firebase is offline. Please check your network or configuration."); |
| } else { |
| console.log("Firebase server connectivity confirmed.", error); |
| } |
| } |
| } |
|
|
| |
| export enum OperationType { |
| CREATE = "create", |
| UPDATE = "update", |
| DELETE = "delete", |
| LIST = "list", |
| GET = "get", |
| WRITE = "write", |
| } |
|
|
| export interface FirestoreErrorInfo { |
| error: string; |
| operationType: OperationType; |
| path: string | null; |
| authInfo: { |
| userId?: string | null; |
| email?: string | null; |
| emailVerified?: boolean | null; |
| }; |
| } |
|
|
| export function handleFirestoreError(error: unknown, operationType: OperationType, path: string | null) { |
| const errInfo: FirestoreErrorInfo = { |
| error: error instanceof Error ? error.message : String(error), |
| authInfo: { |
| userId: auth.currentUser?.uid || null, |
| email: auth.currentUser?.email || null, |
| emailVerified: auth.currentUser?.emailVerified || null, |
| }, |
| operationType, |
| path, |
| }; |
| console.error("Firestore Error Detailed: ", JSON.stringify(errInfo)); |
| throw new Error(JSON.stringify(errInfo)); |
| } |
|
|
|
|