@supabase/middleware is composable, type-safe middleware for Web Fetch handlers. You write per-request logic once and run it on any runtime that supports fetch, or inside Hono, H3, Elysia, NestJS, and TanStack Start with a short bridge you copy. Available now.
@supabase/server has covered the setup step since May, but the per-request logic you add on top, like flag checks, CORS, and what a request needs before your code runs, stays in the handler where you wrote it. Change runtimes and you write it again. Adopt a framework and you rewrite it as that framework's middleware. withSupabase now runs on the @supabase/middleware engine, and @supabase/server ships standalone middleware for each concern that you can combine and reuse.
defineMiddleware writes one piece of per-request logic. It's the same API the Supabase middleware use, and you can publish yours as a packagepipeline([...], handler) runs middleware in order. Each adds one typed key to a shared ctx, and duplicate keys or a middleware ordered before its prerequisite fail to compile on TypeScript 5.4+Response and stop the chain, or modify the response on the way outwithClaims, withRequiredClaims, withSupabaseClient, withSupabaseAdminClient, withPostgresClient, , ) imports from subpaths, and and ship with the engine. and need a TCP socket, so they don't run on Workersnpm install @supabase/middlewareReply here with what you're building, or anything that was unclear when you set it up.
Wendie Cheung introduces @supabase/middleware, a composable, type-safe middleware for Web Fetch handlers. It allows per-request logic to be reused across different runtimes and frameworks. The middleware supports various environments like Supabase Edge Functions, Vercel Functions, and more. Feedback is requested from users on their experiences and any setup challenges.
withPostgresAdminClientwithOAuthProtectedResource@supabase/serverwithCorswithFeatureFlagwithPostgresClientwithPostgresAdminClientwithOAuthProtectedResource plus withSupabase gives your app its own MCP server that an agent calls as the signed-in user, with your RLS policies applied