Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,73 @@ | ||
import { | ||
getApp, | ||
getApps, | ||
initializeApp, | ||
type FirebaseOptions | ||
} from 'firebase/app'; | ||
import { deleteApp, getApp, getApps, initializeApp, type FirebaseOptions } from 'firebase/app'; | ||
import { getAuth } from 'firebase/auth'; | ||
import { getDatabase } from 'firebase/database'; | ||
import { enableLogging, getDatabase } from 'firebase/database'; | ||
import { getFirestore } from 'firebase/firestore'; | ||
import { getStorage } from 'firebase/storage'; | ||
|
||
// NOTE: firebase config with non-auth properties skipped; | ||
const firebaseConfig: FirebaseOptions = | ||
{ | ||
apiKey: import.meta.env?.VITE_FIREBASE_DB_API_KEY as string, | ||
authDomain: import.meta.env?.VITE_FIREBASE_DB_AUTH_DOMAIN_MAIN as string, | ||
projectId: import.meta.env?.VITE_FIREBASE_DB_PROJECT_ID_MAIN as string, | ||
authDomain: import.meta.env?.VITE_FIREBASE_DB_AUTH_DOMAIN as string, | ||
projectId: import.meta.env?.VITE_FIREBASE_DB_PROJECT_ID as string, | ||
databaseURL: import.meta.env?.VITE_FIREBASE_DB_DATABASE_URL as string, | ||
storageBucket: import.meta.env?.VITE_FIREBASE_DB_STORAGE_BUCKET as string | ||
}; | ||
|
||
// DOC: https://stackoverflow.com/questions/37652328/how-to-check-if-a-firebase-app-is-already-initialized-on-android/41005100#41005100 | ||
// NOTE: initialize the Firebase APP; | ||
export const app = | ||
export const app = | ||
getApps().length === 0 | ||
? initializeApp(firebaseConfig) | ||
: getApp() | ||
; | ||
|
||
// version-1 | ||
|
||
// NOTE: Initialize Real-Time-DB and get a reference to the service; | ||
export const db_real = getDatabase(app); | ||
// NOTE: Initialize Firebase Authentication and get a reference to the service; | ||
export const auth = getAuth(app); | ||
// NOTE: Initialize Cloud Storage and get a reference to the service | ||
export const storage = getStorage(app); | ||
// NOTE: Initialize Cloud Firestore and get a reference to the service | ||
export const db_firestore = getFirestore(app); | ||
export const db_firestore = getFirestore(app); | ||
|
||
// version-2 | ||
|
||
export async function firebaseAppDelete | ||
( | ||
) | ||
{ | ||
console.log("🔥 APP DELETED") | ||
await deleteApp | ||
( | ||
app | ||
); | ||
} | ||
|
||
export async function firebaseAppInit | ||
( | ||
) | ||
{ | ||
console.log('(check) initialized Apps', getApps()) | ||
if (getApps().length === 0) | ||
{ | ||
console.log("🔥 INITIALIZING APP") | ||
initializeApp(firebaseConfig) | ||
} | ||
console.log('(post) initialized Apps', getApps()) | ||
} | ||
|
||
// => REAL-TIME DB | ||
export function realDb | ||
( | ||
) | ||
{ | ||
enableLogging(true) | ||
// forceLongPolling() | ||
return getDatabase | ||
( | ||
getApp() | ||
); | ||
} |