| |
| |
| |
| |
|
|
| import { initializeApp } from 'firebase/app'; |
| import { getAuth } from 'firebase/auth'; |
| import { initializeFirestore, doc, getDocFromServer } from 'firebase/firestore'; |
| import firebaseConfig from '../../firebase-applet-config.json'; |
| import { OperationType, FirestoreErrorInfo } from '../types'; |
|
|
| |
| const app = initializeApp(firebaseConfig); |
|
|
| |
| export const db = initializeFirestore(app, { |
| experimentalForceLongPolling: true, |
| }, firebaseConfig.firestoreDatabaseId); |
| export const auth = getAuth(); |
|
|
| |
| |
| |
| 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, |
| email: auth.currentUser?.email, |
| emailVerified: auth.currentUser?.emailVerified, |
| isAnonymous: auth.currentUser?.isAnonymous, |
| tenantId: auth.currentUser?.tenantId, |
| providerInfo: auth.currentUser?.providerData?.map(provider => ({ |
| providerId: provider.providerId, |
| email: provider.email, |
| })) || [] |
| }, |
| operationType, |
| path |
| }; |
| |
| console.error('Firestore Error Tracked: ', JSON.stringify(errInfo)); |
| throw new Error(JSON.stringify(errInfo)); |
| } |
|
|
| |
| |
| |
| async function testConnection() { |
| try { |
| await getDocFromServer(doc(db, 'test', 'connection')); |
| } catch (error) { |
| if (error instanceof Error && error.message.includes('the client is offline')) { |
| console.error("Please check your Firebase configuration or networks. Client appears offline."); |
| } |
| } |
| } |
|
|
| |
| testConnection(); |
|
|