flutterfirebasefirebase-authentication

Read data from Firebase created by loggedin user - Flutter


I've seen a lot of examples online on how to write and read data to Firebase. However, I want to know how to write and read data from Firebase only created by logged in User.

How do we bind such data to a user?

Thanks


Solution

  • It might depend on how your data are oranized. Read through this: https://firebase.google.com/docs/firestore/manage-data/structure-data

    A simple example:

    // snippet for pulling from data once it is there
    await FirebaseFirestore.instance
      .collection("USERDATA")
      .doc(userID)
      .collection('DOCUMENTS')
      .get()
    
    // one way you might supply the function that puts data up to firestore.
    uploadToCloudStorage(
          userID: user.fAuthUser.uid, fileToUpload: File(filePath));