1/** 2 * Firebase v10 modular initialization for the live-event system. 3 * Reuses an existing app instance when another module has already initialized Firebase. 4 * RTDB is added here in a backward-compatible way so Firestore and RTDB can 5 * coexist without changing existing quiz business logic. 6 */ 7 8import { initializeApp, getApp } from "https://www.gstatic.com/firebasejs/10.7.0/firebase-app.js"; 9import { getAuth } from "https://www.gstatic.com/firebasejs/10.7.0/firebase-auth.js"; 10import { getFirestore } from "https://www.gstatic.com/firebasejs/10.7.0/firebase-firestore.js"; 11import { 12 getDatabase, 13 ref, 14 set 15} from "https://www.gstatic.com/firebasejs/10.7.0/firebase-database.js"; 16 17const firebaseConfig = { 18 apiKey: "AIzaSyDF7arzKYkwsictuiYxYGkYrf6hRkpb9sI", 19 authDomain: "science-sangrah-5067f.firebaseapp.com", 20 projectId: "science-sangrah-5067f", 21 // RTDB uses the same Firebase app. Adding the database URL here does not 22 // change Firestore behavior; it only enables safe RTDB access when needed. 23 databaseURL: "https://science-sangrah-5067f-default-rtdb.asia-southeast1.firebasedatabase.app", 24 storageBucket: "science-sangrah-5067f.firebasestorage.app", 25 messagingSenderId: "560169611023", 26 appId: "1:560169611023:web:8259c9db3d2020b4aa587a" 27}; 28 29let app; 30try { 31 app = getApp(); 32} catch (error) { 33 if (error.code !== "app/no-app") { 34 console.error("Firebase App initialization error:", error); 35 throw error; 36 } 37 app = initializeApp(firebaseConfig); 38} 39 40// Existing Firestore and Auth initializers remain unchanged. 41const db = getFirestore(app); 42const auth = getAuth(app); 43// RTDB is initialized from the exact same app instance to avoid duplicate apps. 44const rtdb = getDatabase(app); 45 46/** 47 * Manual RTDB connectivity probe. 48 * This is intentionally not executed automatically so production quiz logic, 49 * listeners, timers, and UI remain untouched until someone calls it explicitly. 50 * 51 * Safe test path: 52 * test/working = true 53 */ 54async function writeRtdbConnectionTest() { 55 await set(ref(rtdb, "test/working"), true); 56 return true; 57} 58 59export { app, auth, db, rtdb, writeRtdbConnectionTest };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.