Add function to get data from Firestore
This commit is contained in:
parent
487818c61a
commit
2f3da54016
23
src/App.js
23
src/App.js
|
@ -7,7 +7,11 @@ import { getAuth,
|
||||||
onAuthStateChanged,
|
onAuthStateChanged,
|
||||||
signOut,
|
signOut,
|
||||||
signInWithEmailAndPassword } from "firebase/auth";
|
signInWithEmailAndPassword } from "firebase/auth";
|
||||||
import { getFirestore } from "firebase/firestore";
|
import { getFirestore,
|
||||||
|
collection,
|
||||||
|
query,
|
||||||
|
where,
|
||||||
|
getDocs } from "firebase/firestore";
|
||||||
|
|
||||||
import { Header } from "./components/Header"
|
import { Header } from "./components/Header"
|
||||||
import './App.css'
|
import './App.css'
|
||||||
|
@ -25,8 +29,8 @@ import { AuthContext } from "./contexts/AuthContext"
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const FBapp = initializeApp(FirebaseConfig)
|
const FBapp = initializeApp(FirebaseConfig)
|
||||||
const FBauth = getAuth()
|
const FBauth = getAuth(FBapp)
|
||||||
const FBdb = getFirestore()
|
const FBdb = getFirestore(FBapp)
|
||||||
|
|
||||||
|
|
||||||
// navigation array
|
// 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 (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<Header items={nav} user={auth} />
|
<Header items={nav} user={auth} />
|
||||||
|
|
|
@ -30,7 +30,7 @@ export function Signup ( props ) {
|
||||||
console.log(auth)
|
console.log(auth)
|
||||||
navigate("/")
|
navigate("/")
|
||||||
}
|
}
|
||||||
}, [auth])
|
}, [auth,])
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
if( username.length >= 4 ) {
|
if( username.length >= 4 ) {
|
||||||
setValidusername(true)
|
setValidusername(true)
|
||||||
|
|
Loading…
Reference in New Issue