• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

362
Views
how to get data in firestore by specific user

The logged in user can also see the activities of other users. but I only want the logged in user's activities to be seen. Do I need to make changes in the query section?

  useEffect(()=>{
    const q = query(collection(db,'etkinlik'));
    const unsub = onSnapshot(q,(snap)=>{
      const array = snap.docs.map(doc=>{
        return{
          id : doc.id,
          title : doc.get('title'),
          start: doc.get('start').toDate(),
          allDay : doc.get('allDay')

        }
      });
      setData([...array]);
    })
    return ()=>{unsub()}
  })  
 const handleDateClick = (args) => {
    if(args.jsEvent.altKey) {
      const title= prompt('Enter Title',args.dateStr);
      const event = {
        title: title ? title : args.dateStr,
        start: args.date,
        allDay: true,
        uid: uid,
        owner: user.uid
      }
      addDoc(collection(db,'etkinlik'),event)
    }
  };
almost 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

How to get data in firestore by specific user?

You're looking for query operators with where, like this:

query(collection(db,'etkinlik'), where('uid', '==', uid));

This will query only for documents that fulfill the where condition. However, this doesn't stop other users from query the data.

I only want the logged in user's activities to be seen

Lock the collection down with Security Rules. For example, to make a collection named etkinlik only readable for clients with a matching uid:

service cloud.firestore {
  match /databases/{database}/documents {
    match /etkinlik {
      allow read: if request.auth.uid == resource.data.uid;
    }
  }
}

Assuming that documents in etkinlik have a field uid (as indicated in your source code example; but you also have owner there, so it depends on you how you use those fields).

See docs, to deploy the Security Rules. It's a good idea to use the Firebase Console and test the rules in the Playground section.

almost 3 years ago · Juan Pablo Isaza Report

0

To restrict a user from seeing certain data (such as other user's data), you will need to develop database rules. Restricting one user from seeing data can also be done locally, but for security reasons you should develop this from the backend.

Security rule instructions for Cloud Firestore and Realtime Datase depending on what you're using.

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error