Skip to main content

Add a new user to a table in a Supabase database

This is a basic task which inserts a new row into a table from a Trigger.dev task.

Key features

  • Shows how to set up a Supabase client using the @supabase/supabase-js library
  • Shows how to add a new row to a table using insert

Prerequisites

  • A Supabase account and a project set up
  • In your Supabase project, create a table called user_subscriptions.
  • In your user_subscriptions table, create a new column:
    • user_id, with the data type: text

Task code

trigger/supabase-database-insert.ts
To learn more about how to properly configure Supabase auth for Trigger.dev tasks, please refer to our Supabase Authentication guide. It demonstrates how to use JWT authentication for user-specific operations or your service role key for admin-level access.

Testing your task

To test this task in the Trigger.dev dashboard, you can use the following payload:
If the task completes successfully, you will see a new row in your user_subscriptions table with the user_id set to user_12345.

Update a user’s subscription on a table in a Supabase database

This task shows how to update a user’s subscription on a table. It checks if the user already has a subscription and either inserts a new row or updates an existing row with the new plan. This type of task is useful for managing user subscriptions, updating user details, or performing other operations you might need to do on a database table.

Key features

  • Shows how to set up a Supabase client using the @supabase/supabase-js library
  • Adds a new row to the table if the user doesn’t exist using insert
  • Checks if the user already has a plan, and if they do updates the existing row using update
  • Demonstrates how to use AbortTaskRunError to stop the task run without retrying if an invalid plan type is provided

Prerequisites

  • A Supabase account and a project set up
  • In your Supabase project, create a table called user_subscriptions (if you haven’t already)
  • In your user_subscriptions table, create these columns (if they don’t already exist):
    • user_id, with the data type: text
    • plan, with the data type: text
    • updated_at, with the data type: timestamptz

Task code

trigger/supabase-update-user-subscription.ts
This task uses your service role secret key to bypass Row Level Security. There are different ways of configuring your RLS policies, so always make sure you have the correct permissions set up for your project.

Testing your task

To test this task in the Trigger.dev dashboard, you can use the following payload:
If the task completes successfully, you will see a new row in your user_subscriptions table with the user_id set to user_12345, the plan set to pro, and the updated_at timestamp updated to the current time.

Learn more about Supabase and Trigger.dev

Full walkthrough guides from development to deployment

Edge function hello world guide

Learn how to trigger a task from a Supabase edge function when a URL is visited.

Database webhooks guide

Learn how to trigger a task from a Supabase edge function when an event occurs in your database.

Supabase authentication guide

Learn how to authenticate Supabase tasks using JWTs for Row Level Security (RLS) or service role keys for admin access.

Task examples with code you can copy and paste

Supabase database operations

Run basic CRUD operations on a table in a Supabase database using Trigger.dev.

Supabase Storage upload

Download a video from a URL and upload it to Supabase Storage using S3.