Supabase for AI SaaS: Auth, Storage, and Signed URLs in Practice

How we use Supabase in a production AI product: magic link auth, JWT verification in Express, private storage with signed URLs, and pgvector on the side.

Ostap Kovalisko

Founder & AI Systems Architect

December 22, 2025•7 min read

Updated 2026-10-19 · Sources and technical review

In this article · 7 min

Supabase gets pitched as "Firebase but Postgres." For AI SaaS it's something more specific: auth, file storage, and a real Postgres you can attach pgvector to — three problems solved with one bill. We run it under a production AI platform with a Next.js frontend and an Express backend on Railway. Here's how the pieces actually fit, including the parts the docs gloss over.

We ship passwordless magic link auth for internal-facing AI products. Business users live in their inbox, there's no password reset flow to support, but the login link and session token are still credentials. Protect the mailbox, redirects and token handling. Three implementation considerations:

  • Send through your own SMTP provider. Supabase's built-in sender is rate-limited (a handful of emails per hour) and lands in spam. Wire SendGrid or similar with your domain and DKIM — this is the #1 "auth is broken" report you'll avoid.
  • Handle the corporate link-scanner problem. Email security tools pre-click links, which can consume one-time tokens. A confirmation page with a button ("Continue to sign in") instead of auto-consuming on GET fixes it.
  • Set session lifetimes for daily-use tools. Nobody should re-authenticate every morning. Long refresh-token life plus an allowlist check at login works for closed B2B products.

The JWT Is the Contract Between Frontend and Backend

Our AI logic lives in Express, not in Supabase edge functions. The integration is simple: the Next.js client attaches the Supabase JWT as a Bearer token; Express verifies it (JWKS or shared secret) and derives the user server-side. Two rules we treat as non-negotiable:

  1. Never accept a user ID from the request body — always derive it from the verified token
  2. Apply the derived permission scope inside retrieval queries, so the agent can't summarize a document its user couldn't open

The service-role key lives only in the backend and the sync workers. It bypasses RLS entirely — treat it like a database password, because it is one.

Storage and Signed URLs: The Pattern That Matters

AI products are file-heavy: users upload contracts and spreadsheets, agents generate reports and charts. All our buckets are private; ordinary public-bucket access is disabled. A signed URL still grants bearer access to whoever holds it until it expires. Access can flow through short-lived signed URLs minted by the backend after a permission check:

FlowPatternURL expiry
User uploadBackend mints signed upload URL → client PUTs directly2 hours for createSignedUploadUrl
Viewing a documentSigned URL per request, after auth checkExample application choice: 1 hour
Agent-generated artifactsWorker writes with service role, stores path in PostgresSigned on read
LLM vision inputShort-lived signed URL passed to the model APIExample application choice: 5 min

Supabase documents a two-hour lifetime for signed upload URLs; do not confuse this with the expiry you select for signed download URLs. Store the storage path in your database, never a signed URL (they expire and end up cached broken in the UI); and route uploads directly to storage via signed upload URLs instead of through your API — proxying multi-megabyte PDFs through Express is a self-imposed bottleneck.

Postgres Is the Quiet Win

The most valuable Supabase feature for AI SaaS is the least flashy one: it's real Postgres. Your app data, your synced records, and your pgvector embeddings live in one database with real joins.

Our sync workers upsert nine sources into Postgres, and pgvector holds 38,000+ embeddings alongside. Retrieval queries can filter by permission, company, and recency in the same statement that ranks by similarity — no cross-store consistency dance with a separate vector DB.

Where We Deviate from the Defaults

  • Know when RLS applies. Requests authorized with the service role bypass row-level security, so RLS cannot catch their authorization mistakes. Enforce tenant and object permissions before privileged calls. See Supabase’s RLS guidance.
  • No heavy logic in edge functions — agent runs are long-lived; they belong on Railway
  • Nightly dumps to separate storage — backups you haven't restored are hypotheses, and synced-in data makes restores messy; practice one

Net: Supabase removes roughly a month of undifferentiated auth and storage work from an AI SaaS build. Spend that month on retrieval quality instead — that's where your product is actually decided.

Frequently asked questions

How do I verify Supabase JWTs in an Express backend?+

Verify the JWT with the method appropriate to the project signing-key configuration: JWKS for asymmetric keys, or the supported verification flow for legacy symmetric signing. Check signature, issuer, audience and expiry, then enforce tenant and object authorization. Decoding a token alone is not verification.

Why use signed URLs instead of making a storage bucket public?+

Private buckets require authorized access; signed URLs are one option, not the only one. Check permissions before issuing a URL and treat it as a bearer credential: anyone who receives it may use it until expiry. The permission check at issuance is not a new user authorization check on every subsequent use.

What is magic link auth and what are its tradeoffs for a SaaS product?+

Magic link auth sends a one-time login link to the user email instead of requiring a password, which removes password storage and reset flows from your responsibility. The tradeoff is a dependency on email deliverability and a slightly slower login, so it fits professional tools where users sign in from a known address more than high-frequency consumer apps.

How does pgvector fit alongside Supabase auth and storage?+

pgvector is a Postgres extension that stores and queries embedding vectors, and since Supabase runs on Postgres you can enable it in the same database you already use for auth and application data. This means you can keep semantic search or retrieval features next to your relational tables without adding a separate vector database.

Let's Talk About Your Project

Have questions about nearshoring or AI development? Our team is here to help you make the right decision.

  • ✓Free consultation on your AI project
  • ✓Custom cost estimates and timeline
  • ✓Access to nearshore talent pools