Periodically delete unused accounts
This sample demonstrates how to delete the accounts of users who have not signed-in in the last month.
See the file functions/index.js for the code.
Cloud Functions does not natively supports cron jobs. We are working around this by executing the code as an HTTPS-triggered function. Then simply use an external service to periodically "ping" the URL.
Here is a non-exhaustive list of external services for cron jobs:
The dependencies are listed in functions/package.json.
The function triggers when the HTTP URL of the Function is requested.
Deploy and test
cron.key Google Cloud environment variables to a randomly generated key. This will be used to authorize requests coming from the 3rd-party cron service. For this use:
firebase functions:config:set cron.key="YOUR-KEY"
You can generate a random key, for instance, by running:
node -e "console.log(require('crypto').randomBytes(20).toString('hex'))"
To set up the sample:
- Create a Firebase Project using the Firebase Developer Console
- Download this sample e.g.
git clone https://github.com/firebase/functions-samples
- Enter the sample directory
- Setup the sample with your project
firebase use --addand follow the instructions.
- Install node dependencies of your Functions
cd functions; npm install; cd -
- Deploy your project using
- Open an account with a 3rd party cron service (e.g. www.setcronjob.com, cron-job.org, www.easycron.com, Zapier ...) and setup a daily cron job to hit the URL (don't forget to change