Server-side code
Database functions, Edge Functions, scheduled jobs and emails, without an API server.
There is no API server. Logic that must run on a server goes, in this order:
- A constraint, trigger or policy, when the rule is about the data (the 25 people on a list and the Sync plan check are triggers).
- A database function called over RPC, when several statements must be one transaction, or a caller needs more than their own rows (the admin area's lists).
- An Edge Function, when it needs a secret or another service (emails, RevenueCat, account deletion).
Database functions
security definer functions live in the private schema with a fixed search_path; a public
RPC checks its caller first (perform private.require_admin()). Clients call them with
supabase.rpc("admin_list_users", { search }), typed from the generated types.
Edge Functions
A function is a plain handler in packages/functions/src/handlers/<name>.ts:
export const deleteAccount: Handler = async (request, deps) => {
const user = await requireUser(request, deps);
// …
return json({ deleted: true });
};Its first lines state the caller: requireUser, requireAdmin, requireSecret (pg_cron) or
verifyWebhook (Supabase Auth hooks). Errors are { error: { code } }, translated by the apps.
bun run functions:build bundles each handler with the workspace code it imports into
supabase/functions/<name>/index.js, which the Edge Runtime serves. Tests call handlers
directly with test dependencies (packages/functions/src/testing.ts).
| Function | Called by |
|---|---|
send-email | Supabase Auth (the email hook) |
send-queued-email | pg_cron, every minute |
delete-account | the apps |
admin-users | the admin area |
revenuecat-webhook | RevenueCat |
sync-entitlements | the native app after a purchase |
reconcile-entitlements | pg_cron, nightly |
health | uptime checks |
Scheduled jobs
pg_cron schedules live in migrations. A job that calls a function reads the URL and the shared secret from Vault:
select cron.schedule('send-queued-email', '* * * * *', $$
select net.http_post(url := private.function_url('send-queued-email'),
headers := private.function_headers(), body := '{}'::jsonb);
$$);Emails
Auth emails (sign-up, sign-in codes, password reset, email change) go through the send-email
hook: one template, the 6-digit code, in the user's language. Every other email is a row in
email_outbox (private.enqueue_email(...)), sent by send-queued-email with retries.
Templates are React Email components in packages/mail; preview them with bun run dev:mail.
Resend sends them in production: Emails.