Home > OS >  setDoc() Called with invalid data. Unsupported field value: undefined
setDoc() Called with invalid data. Unsupported field value: undefined

Time:05-27

I'm trying to create a new firestore document when someone subscribes to my api plan. I want the document id to be the customer id, but i ran into this error.

While the setDoc documentation says that if the document can't be found it will be created with the providing document id. So here is my code:

import { db } from './resources/firebase.js';
import { doc, setDoc } from "firebase/firestore";

await setDoc(doc(db, "customers", customerId), {
                key: hashedApiKey,
                itemId: itemID,
                active: true,
                calls: 0
            });

and here is a screenshot of the firestore side: enter image description here The current entry is just a test value.

Can someone explain me what i'm doing wrong here?

CodePudding user response:

Based on the error message, it is most probably because the value of one of the fields of the document to be saved is undefined, i.e. hashedApiKey or itemID. You should debug your code by printing the values of these two variables.

  • Related