Filter firebase data by logged in user REACT

Viewed 242

I created an app using react and firebase for backend. I have fully working code to authenticate users, they can register and login successfully. They can as well create "cards" on the front end and they get stored on the firebase realtime database. I would like to only display (filter) Cards created by users to be able to be seen only by the user that created it. Right now all and any cards created by users are visible to all users.

Here's how i am adding Cards to the firebase DB, i'm just not sure how to filter by UID:

useEffect(() => {
    const cardRef = firebase.database().ref('Cards')
    cardRef.on('value', (snapshot) => {
      const cards = snapshot.val()
      const cardslist = []
      for (let id in cards) {
        cardslist.push({id, ...cards[id] })
      }
      setCardslist(cardslist)
    })
  },[])

Here is the full project which you can fork and edit: https://codesandbox.io/s/firelog-lpfe5?file=/src/Hero.js:1942-2241

0 Answers
Related