Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/supabase-webhooks-events

@0d57af8
Run it yourself

Implement Supabase database webhooks, pg_net async HTTP, LISTEN/NOTIFY, and Edge Function event handlers with signature verification. Use when setting up database webhooks for INSERT/UPDATE/DELETE events, sending HTTP requests from PostgreSQL triggers, handling Realtime postgres_changes as an event source, or building event-driven architectures. Trigger with phrases like "supabase webhook", "database events", "pg_net trigger", "supabase LISTEN NOTIFY", "webhook signature verify", "supabase event-driven", "supabase_functions.http_request".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/supabase-webhooks-events

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesexamples.md

≈902 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Examples

Testing Webhooks Locally

1. Start Supabase Locally

supabase start
# Note the API URL and service_role key from output

2. Expose Local Edge Function with ngrok

# Serve the Edge Function locally
supabase functions serve on-order-created --env-file .env.local

# In another terminal, expose it
ngrok http 54321
# Copy the HTTPS URL (e.g., https://abc123.ngrok.io)

3. Create the Trigger Pointing to ngrok

-- In local psql or Supabase SQL editor
CREATE OR REPLACE FUNCTION public.test_webhook()
RETURNS trigger AS $$
BEGIN
  PERFORM net.http_post(
    url     := 'https://abc123.ngrok.io/functions/v1/on-order-created',
    headers := '{"Content-Type": "application/json"}'::jsonb,
    body    := jsonb_build_object('type', TG_OP, 'record', row_to_json(NEW)::jsonb)
  );
  RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

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

4. Trigger the Event

# Insert a row to fire the webhook
curl -X POST 'http://localhost:54321/rest/v1/orders' \
  -H "apikey: <anon-key>" \
  -H "Authorization: Bearer <anon-key>" \
  -H "Content-Type: application/json" \
  -d '{"product_id": 1, "quantity": 2, "status": "pending"}'

5. Verify in ngrok Dashboard

Open http://localhost:4040 to see the webhook request in ngrok's inspector.

Manual Webhook Testing with curl

# Simulate an INSERT webhook payload
curl -X POST http://localhost:54321/functions/v1/on-order-created \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <service-role-key>" \
  -d '{
    "type": "INSERT",
    "table": "orders",
    "schema": "public",
    "record": {"id": 42, "product_id": 1, "quantity": 2, "status": "pending"},
    "old_record": null
  }'

# Simulate an UPDATE webhook payload
curl -X POST http://localhost:54321/functions/v1/on-order-created \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <service-role-key>" \
  -d '{
    "type": "UPDATE",
    "table": "orders",
    "schema": "public",
    "record": {"id": 42, "product_id": 1, "quantity": 2, "status": "shipped"},
    "old_record": {"id": 42, "product_id": 1, "quantity": 2, "status": "pending"}
  }'

Realtime Subscription Test (Browser Console)

// Paste in browser console with Supabase JS loaded
const { createClient } = supabase;
const client = createClient(
  "http://localhost:54321",
  "<anon-key>"
);

client
  .channel("test")
  .on("postgres_changes", { event: "*", schema: "public", table: "orders" },
    (payload) => console.log("Realtime event:", payload)
  )
  .subscribe((status) => console.log("Status:", status));

// Now insert a row via curl or the dashboard — you should see the event logged

Auth Hook Test (Custom JWT Claims)

-- Create a user role mapping
INSERT INTO public.user_roles (user_id, role) VALUES
  ('<user-uuid>', 'admin');

-- Create the custom claims hook
CREATE OR REPLACE FUNCTION public.custom_access_token_hook(event jsonb)
RETURNS jsonb AS $$
DECLARE
  user_role text;
BEGIN
  SELECT role INTO user_role
  FROM public.user_roles
  WHERE user_id = (event->>'user_id')::uuid;

  event := jsonb_set(event, '{claims,user_role}', to_jsonb(COALESCE(user_role, 'user')));
  RETURN event;
END;
$$ LANGUAGE plpgsql STABLE;

-- Enable in Dashboard > Auth > Hooks > Custom Access Token

Tons of Skills by Intent Solutions | jeremylongshore.com

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides production-ready templates for Supabase event-driven architectures, including webhooks, Realtime subscriptions, and Postgres LISTEN/NOTIFY. It correctly emphasizes security best practices such as HMAC signature verification and the use of secrets management for sensitive keys. A minor risk is noted regarding the inherent attack surface for indirect prompt injection via external event data.

  • Socket2mo

    2 alerts: gptAnomaly

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
What it can do
Edits files Runs commands
version
1.55.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
compatibility
Designed for Claude Code
All 4 allowed tools
WriteBash(supabase:*)Bash(curl:*)Bash(psql:*)
Other metadata
tags
[
  "saas",
  "supabase",
  "webhooks",
  "events",
  "triggers",
  "pg_net",
  "realtime"
]

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/supabase-webhooks-events