SU

supabase-webhooks-events

Set up database webhooks, LISTEN/NOTIFY, and event handlers with signature verification in Supabase.

Install

mkdir -p .claude/skills/supabase-webhooks-events && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/4808" && unzip -o skill.zip -d .claude/skills/supabase-webhooks-events && rm skill.zip

Installs to .claude/skills/supabase-webhooks-events

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Implement Supabase database webhooks, pg_net async HTTP, LISTEN/NOTIFY,
71 charsno explicit “when” trigger
Advanced

Key capabilities

  • Implement database webhooks using pg_net
  • Call Edge Functions from PostgreSQL triggers
  • Utilize Postgres LISTEN/NOTIFY for pub/sub
  • Handle Realtime postgres_changes for client-side events
  • Verify HMAC-SHA256 signatures for inbound webhooks
  • Implement idempotency for webhook event handling

How it works

The skill uses database triggers with `pg_net` or `LISTEN/NOTIFY` to send events, and Edge Functions or Realtime for event reception and processing.

Inputs & outputs

You give it
Supabase database events (INSERT/UPDATE/DELETE)
You get back
Processed webhook events, client-side event subscriptions, or backend pub/sub messages

When to use supabase-webhooks-events

  • Setting up database webhooks
  • Implementing signature verification
  • Configuring pg_net triggers
  • Handling Realtime event streams

About this skill

Supabase Webhooks & Database Events

Overview

Supabase offers four complementary event mechanisms: Database Webhooks (trigger-based HTTP calls via pg_net), supabase_functions.http_request() (call Edge Functions from triggers), Postgres LISTEN/NOTIFY (lightweight pub/sub), and Realtime postgres_changes (client-side event subscriptions). This skill covers all four patterns with production-ready code including signature verification, idempotency, and retry handling.

Prerequisites

  • Supabase project (local or hosted) with supabase CLI installed
  • pg_net extension enabled: Dashboard > Database > Extensions > search "pg_net" > Enable
  • @supabase/supabase-js v2+ installed for client-side patterns
  • Edge Functions deployed for webhook receiver patterns

Authentication

Both directions of a webhook are authenticated:

  • Outbound (trigger → Edge Function): the trigger sends an Authorization: Bearer <service_role_key> header. Store the key in a Postgres setting (app.settings.service_role_key) or Supabase Vault — never inline it in a committed migration.
  • Inbound (Edge Function receiver): verify an HMAC-SHA256 signature against a shared WEBHOOK_SECRET (read from Deno.env) using a constant-time comparison, and reject mismatches with 401. See signature-verification.md.

Instructions

Pick the mechanism that fits the consumer: pg_net triggers for server-side HTTP fan-out, Edge Function receivers for signed processing, LISTEN/NOTIFY for in-database pub/sub, and Realtime for client UI. Write each SQL trigger to a supabase/migrations/ file and each handler to supabase/functions/<name>/index.ts, then apply and deploy with the supabase CLI.

Step 1 — Database Webhooks with pg_net and Trigger Functions

Enable pg_net, then write a trigger function that POSTs the changed row to an Edge Function. Attach it AFTER INSERT/UPDATE/DELETE. Full trigger set (conditional status-change trigger, the supabase_functions.http_request() built-in helper, and net._http_response inspection queries) is in database-webhooks.md.

CREATE EXTENSION IF NOT EXISTS pg_net WITH SCHEMA extensions;

CREATE OR REPLACE FUNCTION public.notify_order_created()
RETURNS trigger AS $$
BEGIN
  PERFORM net.http_post(
    url     := 'https://<project-ref>.supabase.co/functions/v1/on-order-created',
    headers := jsonb_build_object('Content-Type', 'application/json'),
    body    := jsonb_build_object('type', TG_OP, 'record', row_to_json(NEW)::jsonb)
  );
  RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

CREATE TRIGGER on_order_created
  AFTER INSERT ON public.orders
  FOR EACH ROW EXECUTE FUNCTION public.notify_order_created();

Step 2 — Edge Function Webhook Receivers with Signature Verification

Write an Edge Function that reads the raw body, verifies the HMAC signature, parses the typed payload, and routes by event type. Guard against duplicate delivery with a processed_events idempotency table. The complete receiver, the idempotent-handler variant, and the idempotency table DDL are in edge-function-receivers.md.

// supabase/functions/on-order-created/index.ts
serve(async (req) => {
  const rawBody = await req.text();
  const secret = Deno.env.get("WEBHOOK_SECRET");
  if (secret) {
    const sig = req.headers.get("x-webhook-signature") ?? "";
    if (!(await verifySignature(rawBody, sig, secret)))
      return new Response(JSON.stringify({ error: "Invalid signature" }), { status: 401 });
  }
  const payload = JSON.parse(rawBody); // { type, table, record, old_record }
  // route by payload.type: INSERT | UPDATE | DELETE
  return new Response(JSON.stringify({ received: true }));
});

Step 3 — Postgres LISTEN/NOTIFY and Realtime as Event Source

Use pg_notify from a trigger for lightweight, non-persistent pub/sub consumed by a backend LISTEN; use Realtime postgres_changes for client-side UI subscriptions (keep NOTIFY payloads to IDs — they truncate past 8000 bytes). The backend listener, the full Realtime subscription with event routing, and the combined event-driven architecture diagram are in listen-notify-realtime.md.

const channel = supabase
  .channel("orders-events")
  .on("postgres_changes",
    { event: "*", schema: "public", table: "orders" },
    (payload) => console.log(payload.eventType, payload.new))
  .subscribe();

Output

These patterns produce:

  • Database trigger functions calling Edge Functions via pg_net on row changes
  • Conditional triggers that fire only when specific columns change
  • Edge Function webhook receivers with HMAC signature verification
  • Idempotent event processing preventing duplicate side effects
  • LISTEN/NOTIFY channels for lightweight inter-service communication
  • Realtime subscriptions for live client-side UI updates
  • An event-driven architecture combining server and client patterns

Error Handling

ErrorCauseFix
pg_net returns 404Edge Function not deployed or wrong URLRun supabase functions deploy <name> and verify the URL matches
Webhook not firingTrigger not attached or table not in publicationCheck SELECT * FROM pg_trigger WHERE tgrelid = 'orders'::regclass;
Duplicate events processedNo idempotency layerAdd processed_events table with unique event_id constraint
Realtime not receivingTable not added to Realtime publicationDashboard > Database > Replication > enable the table
net._http_response shows 401Invalid or missing auth headerVerify service_role_key is set in app.settings or vault
NOTIFY payload truncatedPayload exceeds 8000 bytesSend only IDs in NOTIFY, fetch full record in the listener
Auth hook errorsFunction raises exceptionCheck Dashboard > Logs > Auth; ensure function returns valid JSONB
Trigger silently failsSECURITY DEFINER without search_pathAdd SET search_path = public, extensions; to function

Examples

Resources

Next Steps

For performance optimization of triggers and queries, see supabase-performance-tuning. For production hardening including RLS policies on webhook-accessed tables, see supabase-security-basics.

Prerequisites

Supabase project with `supabase` CLI installed`pg_net` extension enabled@supabase/supabase-js v2+ installedEdge Functions deployed for webhook receiver patterns

Limitations

  • NOTIFY payload truncated if it exceeds 8000 bytes

How it compares

This provides production-ready patterns for event-driven architectures, unlike basic webhook setup.

Compared to similar skills

supabase-webhooks-events side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
supabase-webhooks-events (this skill)126dCautionAdvanced
local-cluster-manager226dReviewIntermediate
create-example04moReviewAdvanced
comparing-database-schemas126dReviewAdvanced

Try saying

Example prompts that trigger this skill in your AI assistant.

More by jeremylongshore

View all by jeremylongshore

analyzing-logs

jeremylongshore

Analyze application logs to detect performance issues, identify error patterns, and improve stability by extracting key insights.

14123

ollama-setup

jeremylongshore

Configure auto-configure Ollama when user needs local LLM deployment, free AI alternatives, or wants to eliminate hosted API costs. Trigger phrases: "install ollama", "local AI", "free LLM", "self-hosted AI", "replace OpenAI", "no API costs". Use when appropriate context detected. Trigger with relevant phrases based on skill purpose.

1167

backtesting-trading-strategies

jeremylongshore

Backtest crypto and traditional trading strategies against historical data. Calculates performance metrics (Sharpe, Sortino, max drawdown), generates equity curves, and optimizes strategy parameters. Use when user wants to test a trading strategy, validate signals, or compare approaches. Trigger with phrases like "backtest strategy", "test trading strategy", "historical performance", "simulate trades", "optimize parameters", or "validate signals".

1071

generating-database-seed-data

jeremylongshore

Process this skill enables AI assistant to generate realistic test data and database seed scripts for development and testing environments. it uses faker libraries to create realistic data, maintains relational integrity, and allows configurable data volumes. u... Use when working with databases or data models. Trigger with phrases like 'database', 'query', or 'schema'.

1033

cursor-codebase-indexing

jeremylongshore

Execute set up and optimize Cursor codebase indexing. Triggers on "cursor index setup", "codebase indexing", "index codebase", "cursor semantic search". Use when working with cursor codebase indexing functionality. Trigger with phrases like "cursor codebase indexing", "cursor indexing", "cursor".

885

testing-mobile-apps

jeremylongshore

Execute mobile app testing on iOS and Android devices/simulators. Use when performing specialized testing. Trigger with phrases like "test mobile app", "run iOS tests", or "validate Android functionality".

810

Search skills

Search the agent skills registry