This solution shows how to write a Cloud Function that deletes data in Firestore and securely call this function from your mobile app or website.
- Set up your Firebase project in the
solution-deletes
directory by runningfirebase init
. This solution uses both Firebase Hosting and Cloud Functions for Firebase. - Generate a Firebase token using the
firebase login:ci
command. - Add the token to your Cloud Functions runtime configuration using the
following command:
firebase functions:config:set fb.token="YOUR_TOKEN_HERE"
- Run
firebase deploy --only functions
to deploy the Cloud Functions. - Run
firebase serve --only hosting
to run a local version of the application.
- 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.
- Visit
http://localhost:5000
to 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.