Spaces:
Running
Running
File size: 1,143 Bytes
b72deed 1e7800b b72deed 1e7800b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import { initializeApp, FirebaseApp } from 'firebase/app'
import { getAuth, Auth } from 'firebase/auth'
import { getFirestore, Firestore } from 'firebase/firestore'
const apiKey = import.meta.env.VITE_FIREBASE_API_KEY as string | undefined
const authDomain = import.meta.env.VITE_FIREBASE_AUTH_DOMAIN as string | undefined
const projectId = import.meta.env.VITE_FIREBASE_PROJECT_ID as string | undefined
// True only when all required env vars are present
export const firebaseReady = !!(apiKey && authDomain && projectId)
let app: FirebaseApp | null = null
let _auth: Auth | null = null
let _db: Firestore | null = null
if (firebaseReady) {
app = initializeApp({
apiKey,
authDomain,
projectId,
storageBucket: import.meta.env.VITE_FIREBASE_STORAGE_BUCKET as string | undefined,
messagingSenderId: import.meta.env.VITE_FIREBASE_MESSAGING_SENDER_ID as string | undefined,
appId: import.meta.env.VITE_FIREBASE_APP_ID as string | undefined,
})
_auth = getAuth(app)
_db = getFirestore(app)
}
export const auth = _auth!
export const db = _db!
|