MELLEPRISE MELLEPRISE AI MP Blog
← All articles

supabase webhook fires, but your app never reacts

Pastel comic of a database row sending a small webhook envelope through a queue toward an app window

Your supabase webhook is enabled. The row appears in the table. The trigger exists. Your app still does not create the customer, send the email, update the entitlement, or start the workflow.

What the database webhook really does

A Supabase Database Webhook is a convenience wrapper around a Postgres trigger. After an INSERT, UPDATE, or DELETE, the trigger queues an HTTP request through pg_net. That extension is asynchronous: a slow network call does not block the database write for long.

The key consequence is strict: row commit and webhook delivery are separate. The request starts only after commit; the SQL statement cannot know whether the receiver later returned 200, 401, 500, a timeout, or never ran.

Payload shape matters: inserts use record, updates use record plus old_record, and deletes expose the row only in old_record.

Why AI-built apps hit this so often

The AI usually copies the shortest shape: dashboard webhook, Edge Function URL, one manual row test. That does not prove event, payload, secret header, auth mode, timeout, or duplicate behavior.

supabase webhook production click path

  1. Name the exact business effect. Which row, event, receiver, and resulting state are missing?
  2. Verify table, schema, enabled state, and events in Dashboard → Integrations → Webhooks. Then inspect the actual database trigger definition.
  3. Test with one controlled row change. Manual curl bypasses trigger, payload, transaction boundary, and queue.
  4. Check whether the request is waiting. Waiting requests live in net.http_request_queue and disappear after execution:
select id, method, url, timeout_milliseconds
from net.http_request_queue
order by id desc
limit 20;
  1. Check the HTTP result soon after the test. Responses are stored in net._http_response for a limited window, documented as six hours:
select id, status_code, timed_out, error_msg,
       left(content, 300) as body, created
from net._http_response
order by created desc
limit 20;
  1. Read the result by layer. No response row means queued or never sent; 401/403 is auth; 404 is wrong path; 500 is receiver runtime; timeout means slow path; 200 without effect means a wrong receiver contract.
  2. Check the pg_net worker only when nothing moves:
select pid
from pg_stat_activity
where backend_type ilike '%pg_net%';
  1. Use restart only after evidence. On pg_net 0.8 or later, Supabase documents select net.worker_restart(); for a failed worker. Do not use restart as a blind fix for 401 or a wrong payload.
  2. Inspect Edge Function logs. Confirm start, wrapper rejection, JSON parsing, and downstream API errors. If the function itself is unhealthy, continue with supabase edge functions.
  3. Verify service-to-service auth. The current Supabase pattern sends the project secret key on the apikey header, not as a user JWT. Configure the function for secret-based service-to-service access and set verify_jwt = false for that function.
  4. Check timeout and volume. Row-level triggers can queue one request per row, so bulk imports can flood the queue. Increase timeout only after measuring the slow layer.

The failures that look identical from the app

The transaction committed, but the HTTP request never left. If the transaction rolls back, the asynchronous request is not sent. If the trigger function itself raises an error, the write can fail too. Separate these cases by checking whether the target row and a queue row exist.

The request left, but auth rejected it. A browser test uses a user session. A database webhook carries only the headers configured in the trigger. Missing apikey, an old service-role habit, a wrong project ref, or a function still expecting a browser JWT produces a clean 401 with no app effect.

The receiver returned 200 too early. AI-generated functions often catch every error and return success. pg_net records green while the real job failed. Logs must prove start and completion.

The payload shape was wrong for the event. Delete handlers cannot read the deleted row from record. Update handlers often need both record and old_record to detect transitions. AI-generated receivers frequently assume every event looks like an insert.

Security and data-shape rules before the next retry

A database webhook payload can contain the whole row, including personal or internal fields. If the receiver does not need everything, use a custom trigger function and construct a minimal payload.

Do not paste long-lived secret keys into migration files. Supabase’s Vault pattern stores project URL and secret key outside the migration; a security definer trigger function reads them because roles such as authenticated cannot read Vault.

A dashboard-added secret key is saved in the trigger definition and can appear in trigger SQL or dumps. Treat net.http_request_queue as sensitive too because queued rows contain headers.

Do not put triggers on net._http_response or net.http_request_queue. Supabase warns that triggers on those net tables can recurse or loop when they call pg_net again.

Finally, make the receiver idempotent. Webhook delivery is outside the original transaction; retries, duplicate imports, and timeout ambiguity can repeat effects. Use row id plus event type, a delivery ledger, unique constraints, or a state machine before charging credits, sending email, or provisioning resources.

Production checklist

  • Named business effect and controlled test row exist.
  • Table, schema, events, enabled state, and trigger are verified.
  • The test uses a real row change, not only curl.
  • Queue and response tables are checked together.
  • Edge Function logs prove start and completion.
  • The secret key is sent on apikey; verify_jwt is disabled only for the intended server-to-server function.
  • Secrets are not hard-coded in migrations or casually readable trigger SQL.
  • The payload is minimal and handles insert, update, and delete correctly.
  • Timeouts are measured before they are increased; bulk imports cannot flood the queue unnoticed.
  • All money, email, credit, and provisioning effects are idempotent.
  • The change passes the broader lovable deploy production checklist.

Once you separate commit, queue, HTTP response, receiver execution, and business effect, the failing layer becomes visible. Fix that layer. Do not fix a missing apikey by recreating the trigger or a timeout by resending rows. Treat webhook definitions and trigger functions with the same discipline as supabase migrations.

FAQ

Why does my Supabase webhook not reach my Edge Function?

The database trigger only queues an asynchronous pg_net request after the transaction commits. Check net.http_request_queue for waiting requests, net._http_response for the HTTP result, and the Edge Function logs for receiver-side auth or runtime errors.

Does a successful insert prove the webhook ran?

No. The insert can commit successfully while the webhook request is still queued, times out, returns 401, or fails inside the receiver. Treat the database write and the webhook delivery as separate facts.

Should a Supabase webhook use Authorization Bearer or apikey?

For the current service-to-service Edge Function pattern, send the project secret key on the apikey header and configure the function for secret-based service-to-service access with verify_jwt disabled. New secret keys are not user JWTs.