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.
Login to Supabase
In order for our Edge Functions to work we need to connect them to our existing Supabase account. Login to Supabase via the CLI:
Pushing The Edge Functions
For our Edge Functions to be available in production we need push them to Supabase:
Enabling Supabase Cron Jobs
Cron Jobs are a custom Supabase extension that needs to be enabled. Here’s how to enable the cron jobs extension:
Scheduling The Edge Functions at 00:00
For our last step, we need to schedule our cron jobs to trigger our manage-subscriptions and manage-free-trials edge functions EVERY night at 00:00:00. Here’s how:
Creating a Supabase Edge Function
If needed, it’s also possible to add a new Edge Function using the following command:
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:
or run the following command to run all functions:
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).