Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`firebase_tools.firestore .delete` requires a token, but where does that token come from?

I have a Firebase cloud (callable) function which deletes a firestore document and all child entities, including sub-collections. I'm doing this by slightly modifying the function provided my firebase in their docs: https://firebase.google.com/docs/firestore/solutions/delete-collections

The important bit is here:

...
return firebase_tools.firestore
      .delete(path, {
        project: process.env.GCLOUD_PROJECT,
        recursive: true,
        yes: true,
        token: functions.config().fb.token
      })
...

When I call this function from my webpage (after a user has anthenticated), the web client throws an error that the remote function caused an error. In the firebase console, I find this error:

Unhandled error TypeError: Cannot read property 'token' of undefined

This is pointing to the line in the above code snippet: token: functions.config().fb.token. So .fb is null.

What is going on here?

Searching the web tells me something about login:ci at the command line, but although I'm developing this on my laptop, when the app is deployed, there will be no command line. The website will be on firebase hosting. It makes a call to a firebase cloud function. I'm using firebase auth for user authentication (email/password) and storing data in firestore.

Further, I'm already enabled on my command line, since I can do firebase deploy --only functions just fine. How do I make sure functions.config().fb doesn't return a null??

like image 924
Shahbaz Avatar asked Apr 24 '20 00:04

Shahbaz


People also ask

How do I remove a Subcollection from firestore?

To delete an entire collection or subcollection in Cloud Firestore, retrieve all the documents within the collection or subcollection and delete them. If you have larger collections, you may want to delete the documents in smaller batches to avoid out-of-memory errors.

Which of the following method is used to delete a field from a particular document in firebase?

Deleting Fields For deleting a specific field from a document, use the FieldValue. delete() method when we update a document.

How do I delete data from Firebase?

"Firebase. remove() - Remove the data at this Firebase location. Any data at child locations will also be deleted. The effect of the delete will be visible immediately."

How do I delete multiple files on firestore?

To delete multiple documents, you can do a single batched write. The WriteBatch class has a delete() method for this purpose. The performance to between a single BatchedWrite and multiple DocumentReference.


1 Answers

If you want, you can just paste the token string directly into the code, replacing functions.config().fb.token. The authors of that page probably figured you didn't want to do that, so they suggested you should create a configuration item for it instead.

If you don't want to paste it in, and you actually want to configure the function to get that value from configuration, you will have to set the config on the command line using functions:config:set like this:

firebase functions:config:set fb.token=<YOUR-TOKEN>

The deploy your function again so it can use that value.

If you found the documentation confusing, I suggest using the "send feedback" link at the top right of the page.

like image 151
Doug Stevenson Avatar answered Oct 20 '22 01:10

Doug Stevenson