---
title: "Supabase Middleware: composable, reusable middleware for Web Fetch handlers"
description: "`@supabase/middleware` is an MIT-licensed, type-safe middleware engine for Web Fetch handlers."
url: "https://swe.quest/articles/supabase-middleware-composable-reusable-middleware-for-web-fetch-handlers-136b7931628c402b"
canonical: "https://supabase.com/blog/supabase-middleware"
source: "Supabase"
published: "2026-10-15"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 8
tags: ["typescript","serverless","identity-auth","api-design","ai-agents"]
---

# Supabase Middleware: composable, reusable middleware for Web Fetch handlers

A post on [Supabase](https://swe.quest/sources/supabase.md), published 2026-10-15, 8 min read, Announcement. Original: [https://supabase.com/blog/supabase-middleware](https://supabase.com/blog/supabase-middleware)

## Summary

\`@supabase/middleware\` is an MIT-licensed, type-safe middleware engine for Web Fetch handlers. Per-request logic such as CORS, JWT claim verification, feature flags, RLS-scoped Supabase/Postgres clients and MCP OAuth discovery is composed as an ordered pipeline that each adds a typed key to a shared ctx, can short-circuit with a Response, or modify the response on the way out. The pipeline is a plain fetch handler, so it runs on Edge Functions, Vercel, Cloudflare Workers, Deno, Bun and Node 22+. Copy-in bridge files reuse the same entries in Hono, H3, Elysia, NestJS and TanStack Start. Custom middleware is written with \`defineMiddleware\`, whose type parameters make duplicate keys or misordered dependencies fail to compile (TypeScript 5.4+). The pg-based clients don't work on Workers because they need TCP sockets.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [Identity & auth](https://swe.quest/tags/identity-auth.md) (Security)
- [API design](https://swe.quest/tags/api-design.md) (Backend & APIs)
- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)

## Prerequisites

- Web Fetch API Request/Response
- TypeScript generics ([easy posts on TypeScript](https://swe.quest/tags/typescript.md?difficulty=easy))
- JWT authentication ([easy posts on Identity & auth](https://swe.quest/tags/identity-auth.md?difficulty=easy))
- Postgres row-level security ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))

## Keywords

@supabase/middleware, @supabase/server, Supabase Edge Functions, Hono, Cloudflare Workers, MCP, OAuth protected resource, Row Level Security

## Related posts

- [Introducing @supabase/server](https://swe.quest/articles/introducing-supabase-server-014f7e505754650d.md): Supabase · 2026-05-06 · Medium · 8 min read · Identity & auth, Serverless, TypeScript, Developer tools
  @supabase/server, now in public beta, replaces the repeated setup code found across 25,000 analyzed Edge Functions: client creation, JWT verification, claims parsing, CORS and auth wiring.
- [Edge Functions are now available in Supabase](https://swe.quest/articles/edge-functions-are-now-available-in-supabase-3c06235615e01037.md): Supabase · 2022-03-31 · Easy · 7 min read · Serverless, CDN & edge, TypeScript, System design
  Supabase Edge Functions run TypeScript globally on the Deno runtime via Deno Deploy across 30+ data centers.
- [supabase-js v2](https://swe.quest/articles/supabase-js-v2-f87cba2e3b41f9e9.md): Supabase · 2022-08-16 · Medium · 5 min read · JavaScript, TypeScript, API design, Identity & auth, PostgreSQL
  supabase-js v2 brings incremental quality-of-life changes over v1.
- [Give your Supabase app its own MCP server](https://swe.quest/articles/give-your-supabase-app-its-own-mcp-server-db89f29412fb7983.md): Supabase · 2026-10-22 · Medium · 5 min read · AI agents, Identity & auth, PostgreSQL, Serverless, TypeScript
  Supabase apps can expose their own MCP server so customers use the app from ChatGPT, Claude or other MCP clients, signed in with their existing account.
- [Supabase Edge Runtime: Self-hosted Deno Functions](https://swe.quest/articles/supabase-edge-runtime-self-hosted-deno-functions-55b12d1d5db96506.md): Supabase · 2023-04-11 · Medium · 7 min read · Serverless, Runtimes & VMs, JavaScript, Rust, Open source
  Supabase Edge Runtime is an MIT-licensed, Rust-based web server built on deno\_core that self-hosts Deno Edge Functions (TypeScript, JavaScript, WASM) without code changes.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
