File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js" ;
2+ import { getFirestore } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js" ;
3+
4+ const firebaseConfig = {
5+ apiKey : "AIzaSyCUHWXemBpfAWOSDqj1_rY6s4oQr27FnKg" ,
6+ authDomain : "noctive-41c22.firebaseapp.com" ,
7+ projectId : "noctive-41c22" ,
8+ storageBucket : "noctive-41c22.firebasestorage.app" ,
9+ messagingSenderId : "617642134193" ,
10+ appId : "1:617642134193:web:ea5f0c93e56c654f66f090" ,
11+ measurementId : "G-8ZFW3MTB3C"
12+ } ;
13+
14+ const app = initializeApp ( firebaseConfig ) ;
15+ const db = getFirestore ( app ) ;
16+
17+ export { db } ;
Original file line number Diff line number Diff line change 1+ import { db } from "./firebase.js" ;
2+ import {
3+ collection ,
4+ getDocs
5+ } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js" ;
6+
7+ async function loadPosts ( ) {
8+ const container = document . getElementById ( "firebasePosts" ) ;
9+
10+ if ( ! container ) return ;
11+
12+ container . innerHTML = "Loading..." ;
13+
14+ try {
15+ const querySnapshot = await getDocs ( collection ( db , "Posts" ) ) ;
16+
17+ container . innerHTML = "" ;
18+
19+ querySnapshot . forEach ( ( doc ) => {
20+ const data = doc . data ( ) ;
21+
22+ const div = document . createElement ( "div" ) ;
23+ div . textContent = data . text ;
24+
25+ container . appendChild ( div ) ;
26+ } ) ;
27+
28+ } catch ( err ) {
29+ console . error ( err ) ;
30+ container . innerHTML = "Error loading posts" ;
31+ }
32+ }
33+
34+ document . addEventListener ( "DOMContentLoaded" , loadPosts ) ;
Original file line number Diff line number Diff line change 23812381
23822382 setAuthMode ( true ) ;
23832383 </ script >
2384+ < div id ="firebasePosts "> </ div >
2385+ < script type ="module " src ="../js/main.js "> </ script >
23842386</ body >
23852387</ html >
23862388
You can’t perform that action at this time.
0 commit comments