Solution: Recursive Deletes
This solution shows how to write a Cloud Function that deletes data in Cloud Firestore and securely call this function from your mobile app or website.
On your development machine
- Set up your Firebase project in the
solution-deletesdirectory by running
firebase init. This solution uses both Firebase Hosting and Cloud Functions for Firebase.
- Generate a Firebase token using the
- Add the token to your Cloud Functions runtime configuration using the
firebase functions:config:set fb.token="YOUR_TOKEN_HERE"
firebase deploy --only functionsto deploy the Cloud Functions.
firebase serve --only hostingto run a local version of the application.
In your browser
- Enable the Identity and Access Management (IAM) API on your project in the Google Cloud console by visiting: https://console.developers.google.com/apis/api/iam.googleapis.com/overview
- In the IAM page of the Google Cloud console, find the service account called the "App Engine default service account" and grant it the "Service Account Token Creator" role.
http://localhost:5000to see the running sample.
- Click the SIGN IN button. This will call the Cloud Function you deployed to generate a custom sign in token, and then use that token to sign in on the client.
- Enter the path of the document or collection you would like
to delete, for example
things/thing1, then click DELETE.