Building a multi-tenant SaaS where couples create private or semi-public event pages — with optional guest PIN gates and private photo galleries — on TanStack Start (React 19 + Node) and PostgreSQL (Supabase) taught us several subtle failure modes where Postgres defaults, RLS evaluation rules, and bundler code-splitting behave differently than you might expect.
Here are four production lessons we ran into and the patterns we use to keep them locked down.
1. Why REVOKE EXECUTE ... FROM anon, authenticated is a silent no-op
In PostgreSQL, newly created functions grant EXECUTE to the PUBLIC pseudo-role by default. Because every role (including anon and authenticated) inherits privileges granted to PUBLIC, running:
REVOKE EXECUTE ON FUNCTION public.is_wedding_owner(uuid) FROM anon, authenticated; does nothing at all. Querying has_function_privilege('anon', 'public.is_wedding_owner(uuid)', 'EXECUTE') still returns true.
You must revoke from PUBLIC first, explicitly grant only to the roles that need execution, and lock down future objects via default privileges:
REVOKE ALL ON FUNCTION public.is_wedding_owner(uuid) FROM PUBLIC; GRANT EXECUTE ON FUNCTION public.is_wedding_owner(uuid) TO authenticated; ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC; ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON TABLES FROM PUBLIC, anon, authenticated; To ensure a migration never drifts, we run a nightly SQL catalog invariant suite checking has_table_privilege, has_sequence_privilege, and has_function_privilege across public so anon holds zero privileges on any relation or function.
2. Inline joins inside RLS policies silently return 0 rows when the parent is fail-closed
Our parent tenant table, public.weddings, has RLS enabled with zero policies. All reads and writes to weddings go through server-side code using the service role.
If you write a child table policy (for example on rsvps or gifts) using an inline EXISTS subquery against weddings:
-- Fails closed silently if public.weddings has 0 RLS policies! CREATE POLICY "owners read rsvps" ON public.rsvps FOR SELECT TO authenticated USING ( EXISTS ( SELECT 1 FROM public.weddings w WHERE w.id = wedding_id AND w.owner_id = auth.uid() ) ); Postgres evaluates that subquery under the querying role (authenticated), hits the zero-policy parent table, and silently returns zero rows instead of throwing a permission error.
The clean fix is a SECURITY DEFINER predicate with a pinned search_path:
CREATE OR REPLACE FUNCTION public.is_wedding_owner(p_wedding_id uuid) RETURNS boolean LANGUAGE sql STABLE SECURITY DEFINER SET search_path TO 'public', 'pg_temp' AS $$ SELECT EXISTS ( SELECT 1 FROM public.weddings w WHERE w.id = p_wedding_id AND w.owner_id = auth.uid() ); $$; Pinning SET search_path TO 'public', 'pg_temp' prevents search-path hijacking while keeping public.weddings completely closed to direct client queries.
3. Permanent WhatsApp og:image URLs without public storage buckets
In Brazil, wedding invitations are shared primarily in WhatsApp groups, where link previews cache og:image URLs for weeks or months.
Making your storage bucket public gives you permanent URLs, but it completely bypasses application-level publish gates and guest PIN protection. Returning expiring signed URLs directly in og:image protects access, but breaks social previews once the token expires.
Our pattern keeps every storage bucket private and serves photos through a thin route on our own origin, /api/photo/<bucket>/<path>:
export async function handlePhotoRequest( bucket: string, objectPath: string, pinCookie?: string, ) { const wedding = await resolveWeddingByAssetPath(bucket, objectPath); if (!wedding || !wedding.isPublished) { return new Response('Not found', { status: 404 }); } if (wedding.pinHash && !(await verifyGuestPinCookie(wedding.id, pinCookie))) { return new Response('Forbidden', { status: 403 }); } const signedUrl = await createShortLivedSignedUrl(bucket, objectPath, 60); return Response.redirect(signedUrl, 302); } WhatsApp's link preview crawler follows the 302 redirect to fetch the image, while the canonical og:image URL stays stable on our domain and immediately respects unpublishing or PIN changes.
4. Keeping zod out of client entry chunks in TanStack Start
TanStack Start's compiler strips createServerFn .handler(...) and .inputValidator(...) callbacks from client bundles and replaces them with RPC stubs.
However, when we exported z.object(...) schemas directly from *.functions.ts files so client components could reuse types or form validators, Vite saw module-level exports inside the client import graph and kept zod inside browser entry chunks.
Separating schemas into pure *.schemas.ts modules — leaving *.functions.ts purely for RPC boundaries — fixed the leak, and a Vitest check against the production client manifest now fails CI if zod shows up in unexpected entry chunks:
// weddings.schemas.ts (imported only where client forms need runtime validation) import { z } from 'zod'; export const rsvpInputSchema = z.object({ weddingId: z.string().uuid(), guestName: z.string().min(2).max(120), attending: z.boolean(), }); // weddings.functions.ts (RPC boundary only — no schema re-exports) import { createServerFn } from '@tanstack/react-start'; import { rsvpInputSchema } from './weddings.schemas'; export const submitRsvp = createServerFn({ method: 'POST' }) .inputValidator((data: unknown) => rsvpInputSchema.parse(data)) .handler(async ({ data }) => saveRsvpInPostgres(data)); Production context
These four patterns power Viva Love, a bilingual (pt-BR / en) wedding website and planning platform built for couples getting married in Brazil. Couples can build and preview their entire site free with no time limit and pay once (R$ 149 / €29, no subscription) only when ready to publish — with 0%-fee direct Pix gift QR codes straight into the couple's bank account, PIN-protected RSVP, PDF/Excel seating exports, and noindex privacy by default for couples' sites (see our live interactive example).
We also maintain 12 free, zero-signup Brazilian wedding planning calculators (budget, drinks, buffet, guest list, and more) at viva-love.com.br/ferramentas. If you have hit similar Postgres RLS or TanStack Start bundling gotchas, feel free to share in the comments.

