Supabase Edge Functions
In this section, we’ll go through the steps on how to enable cron jobs using Edge Functions in Supabase, so that expired Free Trials and Subscriptions are automatically cancelled.
Importing .env Variables
In order for our Edge Functions to work we need to import all of our existing .env variables into our project. You just need to import the following variable: LOOPS_API_KEY
- which is used for sending emails.
Enabling Supabase Cron Jobs
It’s possible to schedule cron jobs to run at specific times. In our case we run them at midnight EVERY night at 00:00:00. Here’s how to enable them:
Creating a Supabase Edge Function
If needed, it’s also possible to add a new Edge Function using the following command:
npx supabase functions new [function-name]
Testing a Function on Localhost
Pre-Requisites: In order to test Supabase Edge Functions on localhost, please ensure to have Docker Desktop installed. You can download it from [here].
You can start a Supabase Edge Function with the following command:
npx supabase functions serve [function-name]
or run the following command to run all functions:
npm run functions:listen
In order to test the function, please call the following endpoint using Postman with the appropriate HTTP method such as GET, POST, etc. You should now see the console.logs right in the terminal (if present in the function).
http://localhost:54321/functions/v1/[function-name]