Push notifications from Supabase
Supabase has several ways to trigger code when data changes. Here’s how to turn any of them into a phone notification.
Auth signups via Database Webhooks
The most common use case: notify when a new user signs up.
In Supabase Dashboard: Database → Webhooks → Create a new hook
- Table:
auth.users - Events:
INSERT - URL: your Edge Function or external endpoint
Then in your handler:
// supabase/functions/on-user-signup/index.ts
import fyi from "npm:trigger.fyi"
Deno.serve(async (req) => {
const payload = await req.json()
const user = payload.record
await fyi("New signup", {
body: user.email,
provider: user.raw_app_meta_data?.provider ?? "email"
})
return new Response("OK")
})Deploy it:
supabase functions deploy on-user-signupEdge Functions for any table event
Listen to any table change:
// supabase/functions/on-order-created/index.ts
import fyi from "npm:trigger.fyi"
Deno.serve(async (req) => {
const { type, record, table } = await req.json()
if (type === "INSERT" && table === "orders") {
await fyi(`Order #${record.id}`, {
body: `$${record.total} · ${record.customer_email}`,
status: record.status
})
}
return new Response("OK")
})Realtime subscriptions (client-side)
If you have a dashboard or admin panel that’s always open, Supabase Realtime can trigger notifications directly from the browser:
import { createClient } from "@supabase/supabase-js"
import fyi from "trigger.fyi"
const supabase = createClient(url, anonKey)
supabase
.channel("orders")
.on("postgres_changes", { event: "INSERT", schema: "public", table: "orders" }, (payload) => {
fyi(`New order: #${payload.new.id}`, {
body: `$${payload.new.total}`,
status: payload.new.status
})
})
.subscribe()This only works while the browser tab is open. For always-on notifications, use Edge Functions or a Database Webhook instead.
In a Supabase Edge Function: fire-and-forget
Deno.serve waits for the response, so await fyi() is the cleanest pattern. It never throws and completes in one roundtrip:
Deno.serve(async (req) => {
const payload = await req.json()
// Your logic here
const result = await processPayload(payload)
// Notify
await fyi("Processed", { body: result.id })
return new Response(JSON.stringify(result), {
headers: { "Content-Type": "application/json" }
})
})Environment variable in Edge Functions
Add to your Supabase project secrets:
supabase secrets set TRIGGER_FYI_SECRET_KEY=your_key_hereAccess in the function via Deno.env.get("TRIGGER_FYI_SECRET_KEY"). The trigger.fyi npm package reads process.env.TRIGGER_FYI_SECRET_KEY — in Deno, this maps through the Node.js compatibility layer.
Or use Deno.env.get directly with a plain fetch:
const key = Deno.env.get("TRIGGER_FYI_SECRET_KEY")
if (key) {
await fetch(`https://trigger.fyi/${key}`, {
method: "POST",
body: "Something happened"
})
}Filtering by table or event type
Use metadata to make the feed filterable:
await fyi("Database change", {
body: `${record.id}`,
table: table,
event: type,
schema: schema
})Open the terminal feed (npx trigger.fyi) and filter by table: orders to see only order events.
Setup
npx trigger.fyiGenerates a key, subscribes your device. Then:
supabase secrets set TRIGGER_FYI_SECRET_KEY=your_key_hereDeploy your Edge Function, configure the webhook, done.
Related: Push notifications from Next.js · Push notifications from Cloudflare Workers · Deploy notifications on your phone · What is trigger.fyi?