You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e34510b
Browse filesBrowse the repository at this point in the historyBrowse files
docs: use @supabase/server in Supabase database operations guide
Replace manual jsonwebtoken signing and createClient with @supabase/server
core primitives: verifyCredentials + createContextClient for the
user-scoped insert example, and createAdminClient for the admin example.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JGxYWHGbdiQ1BwXWY92dJ4
Copy file name to clipboardExpand all lines: docs/guides/examples/supabase-database-operations.mdx
+63-39Lines changed: 63 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,53 +13,68 @@ This is a basic task which inserts a new row into a table from a Trigger.dev tas
13
13
14
14
### Key features
15
15
16
-
- Shows how to set up a Supabase client using the `@supabase/supabase-js` library
16
+
- Shows how to verify a user's Supabase access token using the [`@supabase/server`](https://github.com/supabase/server) package
17
+
- Shows how to create a user-scoped Supabase client, so your [Row Level Security (RLS) policies](https://supabase.com/docs/guides/database/postgres/row-level-security) apply
17
18
- Shows how to add a new row to a table using `insert`
18
19
19
20
### Prerequisites
20
21
21
22
- A [Supabase account](https://supabase.com/dashboard/) and a project set up
23
+
- Your project uses the new [API keys](https://supabase.com/docs/guides/api/api-keys) (`sb_publishable_...` / `sb_secret_...`) and [JWT signing keys](https://supabase.com/docs/guides/auth/signing-keys). `@supabase/server` does not accept legacy `anon` / `service_role` keys or HS256-signed JWTs.
22
24
- In your Supabase project, create a table called `user_subscriptions`.
23
25
- In your `user_subscriptions` table, create a new column:
24
26
-`user_id`, with the data type: `text`
27
+
- An RLS policy on `user_subscriptions` that allows authenticated users to insert their own row, for example `with check (auth.uid()::text = user_id)`
28
+
29
+
### Installation
30
+
31
+
Install `@supabase/server` and its `@supabase/supabase-js` peer dependency:
Add these to your project's [environment variables](/deploy-environment-variables) in the Trigger.dev dashboard:
40
+
41
+
-`SUPABASE_URL`: your project URL, e.g. `https://<project-ref>.supabase.co`
42
+
-`SUPABASE_PUBLISHABLE_KEY`: your publishable key (`sb_publishable_...`)
43
+
44
+
The JWKS used to verify user tokens is derived automatically from `SUPABASE_URL`.
25
45
26
46
### Task code
27
47
48
+
Your app triggers this task with the signed-in user's access token (for example `session.access_token` from `supabase.auth.getSession()`). The task verifies the token, then queries the database as that user.
If the task completes successfully, you will see a new row in your `user_subscriptions` table with the `user_id` set to `user_12345`.
112
+
If the task completes successfully, you will see a new row in your `user_subscriptions` table with the `user_id` set to that user's ID.
92
113
93
114
## Update a user's subscription on a table in a Supabase database
94
115
@@ -98,7 +119,7 @@ This type of task is useful for managing user subscriptions, updating user detai
98
119
99
120
### Key features
100
121
101
-
- Shows how to set up a Supabase client using the `@supabase/supabase-js` library
122
+
- Shows how to create an admin Supabase client using the [`@supabase/server`](https://github.com/supabase/server) package
102
123
- Adds a new row to the table if the user doesn't exist using `insert`
103
124
- Checks if the user already has a plan, and if they do updates the existing row using `update`
104
125
- Demonstrates how to use [AbortTaskRunError](https://trigger.dev/docs/errors-retrying#using-aborttaskrunerror) to stop the task run without retrying if an invalid plan type is provided
@@ -113,25 +134,24 @@ This type of task is useful for managing user subscriptions, updating user detai
113
134
-`plan`, with the data type: `text`
114
135
-`updated_at`, with the data type: `timestamptz`
115
136
137
+
### Environment variables
138
+
139
+
Add these to your project's [environment variables](/deploy-environment-variables) in the Trigger.dev dashboard:
140
+
141
+
-`SUPABASE_URL`: your project URL, e.g. `https://<project-ref>.supabase.co`
142
+
-`SUPABASE_SECRET_KEY`: your secret key (`sb_secret_...`)
0 commit comments