Authenticating Supabase tasks: JWTs and service roles
Learn how to authenticate Supabase tasks using JWTs for Row Level Security (RLS) or service role keys for admin access.
There are two ways to authenticate your Supabase client in Trigger.dev tasks:
1. Using JWT Authentication (Recommended for User-Specific Operations)
A JWT (JSON Web Token) is a string-formatted data container that typically stores user identity and permissions data. Row Level Security policies are based on the information present in JWTs. Supabase JWT docs can be found here.
To use JWTs with Supabase, you’ll need to add the SUPABASE_JWT_SECRET
environment variable in your project. This secret is used to sign the JWTs. This can be found in your Supabase project settings under Data API
.
This example code shows how to create a JWT token for a user and initialize a Supabase client with that token for authentication, allowing the task to perform database operations as that specific user. You can adapt this code to fit your own use case.
Using JWTs to authenticate Supabase operations is more secure than using service role keys because it respects Row Level Security policies, maintains user-specific audit trails, and follows the principle of least privileged access.
2. Using Service Role Key (For Admin-Level Access)
The service role key has unlimited access and bypasses all security checks. Only use it when you need admin-level privileges, and never expose it client-side.
This example code creates a Supabase client with admin-level privileges using a service role key, bypassing all Row Level Security policies to allow unrestricted database access.
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
Was this page helpful?