Search code examples
reactjsfirebasegoogle-cloud-firestorefirebase-authentication

Why does the document keep the original data when I update it? It is returned into the previous status right away. No error


I have a collection with a lot of documents in Firestore Database. I wrote a function to update the data of a document in React.

try {

    await firebase.app
        .firestore()
        .collection("Records")
        .doc(recordId)
        .update({ public: value, _author: UserProfile.getEmail() });
           
    return {
        status: status.SUCCESS
    }

} catch(error) {
    return {
        status: status.INTERNAL_SERVER_ERROR
    }
}

I am updating the document as an authenticated user, and for other documents, the update function works correctly. But it doen't work only for a few records.

I checked the permission of the user in Authentication of Firebase. Everything was enabled there.

Here is an example of the document. enter image description here


Solution

  • I have experienced the issue before. I am sure that it is a permission issue. You can add "Access" field into the document. The "Access" field consists of "Edit", "Exec", "Owner", "Read", etc.

    "Access": {
        "Exec": ["[email protected]"],
        "Owner": ["[email protected]"],
        ...
    }
    

    When I add the user's email into "Owner" array, it worked.