From 2f3da5401673d33591aa74da2ea15c11e7c0786c Mon Sep 17 00:00:00 2001 From: "Rayyan (Rayy)" Date: Tue, 17 Oct 2023 08:46:28 +0000 Subject: [PATCH] Add function to get data from Firestore --- src/App.js | 23 ++++++++++++++++++++--- src/pages/Signup.js | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index a6dcd5d..3171cb8 100644 --- a/src/App.js +++ b/src/App.js @@ -7,7 +7,11 @@ import { getAuth, onAuthStateChanged, signOut, signInWithEmailAndPassword } from "firebase/auth"; -import { getFirestore } from "firebase/firestore"; +import { getFirestore, + collection, + query, + where, + getDocs } from "firebase/firestore"; import { Header } from "./components/Header" import './App.css' @@ -25,8 +29,8 @@ import { AuthContext } from "./contexts/AuthContext" function App() { const FBapp = initializeApp(FirebaseConfig) - const FBauth = getAuth() - const FBdb = getFirestore() + const FBauth = getAuth(FBapp) + const FBdb = getFirestore(FBapp) // navigation array @@ -98,6 +102,19 @@ const signIn = (email, password) => { }) }) } + +// function to get data +const readData = async () => { + const querySnapshot = await getDocs( collection(FBdb, "books") ) + let data = [] + querySnapshot.forEach( (doc) => { + let item = doc.data() + item.id = doc.id + data.push( item ) + }) +} + + return (
diff --git a/src/pages/Signup.js b/src/pages/Signup.js index 8bd18fb..256fe97 100644 --- a/src/pages/Signup.js +++ b/src/pages/Signup.js @@ -30,7 +30,7 @@ export function Signup ( props ) { console.log(auth) navigate("/") } - }, [auth]) + }, [auth,]) useEffect( () => { if( username.length >= 4 ) { setValidusername(true)