File tree Expand file tree Collapse file tree 6 files changed +161
-9
lines changed
Expand file tree Collapse file tree 6 files changed +161
-9
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ rules_version = '2';
22
33service cloud .firestore {
44 match / databases/ {database }/ documents {
5- match / {document =** } {
6- allow read , write : if false ;
5+
6+ match / blogs/ {blogId } {
7+ allow read : if true ;
8+ allow write : if request .auth != null ;
79 }
810 }
9- }
11+ }
Original file line number Diff line number Diff line change 1111 },
1212 "dependencies" : {
1313 "@firebasegen/default-connector" : " file:dataconnect-generated/js/default-connector" ,
14+ "axios" : " ^1.7.9" ,
1415 "firebase" : " ^11.2.0" ,
1516 "react" : " ^18.3.1" ,
1617 "react-dom" : " ^18.3.1" ,
Original file line number Diff line number Diff line change 33interface ImportMetaEnv {
44 readonly VITE_FIREBASE_API_KEY : string ;
55 readonly VITE_FIREBASE_AUTH_DOMAIN : string ;
6- readonly VITE_FIREBASE_DATABASE_URL : string ;
76 readonly VITE_FIREBASE_PROJECT_ID : string ;
87 readonly VITE_FIREBASE_STORAGE_BUCKET : string ;
98 readonly VITE_FIREBASE_MESSAGING_SENDER_ID : string ;
Original file line number Diff line number Diff line change 1+ import { useEffect , useState } from "react" ;
2+ import { collection , getDocs } from "firebase/firestore" ;
3+ import { db } from "../../config/firebaseConfig" ;
4+
5+ interface Blog {
6+ id : string ;
7+ title : string ;
8+ content : string ;
9+ author : string ;
10+ tags : string [ ] ;
11+ createdAt : { seconds : number } ;
12+ }
113
214const Home = ( ) => {
15+ const [ blogs , setBlogs ] = useState < Blog [ ] > ( [ ] ) ;
16+
17+ useEffect ( ( ) => {
18+ const fetchBlogs = async ( ) => {
19+ try {
20+ const querySnapshot = await getDocs ( collection ( db , "Blogs" ) ) ;
21+ const blogsData = querySnapshot . docs . map ( ( doc ) => ( {
22+ id : doc . id ,
23+ ...doc . data ( ) ,
24+ } ) ) as Blog [ ] ;
25+ setBlogs ( blogsData ) ;
26+ console . log ( blogsData ) ;
27+ } catch ( error ) {
28+ console . error ( "Error fetching blogs:" , error ) ;
29+ }
30+ } ;
31+
32+ fetchBlogs ( ) ;
33+ } , [ ] ) ;
34+
335 return (
4- < div > Home</ div >
5- )
6- }
36+ < div >
37+ < h1 > Blogs</ h1 >
38+ { blogs . map ( ( blog ) => (
39+ < div key = { blog . id } >
40+ < h2 > { blog . title } </ h2 >
41+ < p > { blog . content } </ p >
42+ < p >
43+ < strong > Author:</ strong > { blog . author }
44+ </ p >
45+ < p >
46+ < strong > Tags:</ strong > { blog . tags . join ( ", " ) }
47+ </ p >
48+ < p >
49+ < strong > Created At:</ strong > { " " }
50+ { new Date ( blog . createdAt . seconds * 1000 ) . toLocaleString ( ) }
51+ </ p >
52+ </ div >
53+ ) ) }
54+ </ div >
55+ ) ;
56+ } ;
757
8- export default Home
58+ export default Home ;
Original file line number Diff line number Diff line change 2222 "noFallthroughCasesInSwitch" : true ,
2323 "noUncheckedSideEffectImports" : true
2424 },
25- "include" : [" src" ]
25+ "include" : [" src" , " src/env.d.ts " ]
2626}
You can’t perform that action at this time.
0 commit comments