Supabase Middleware 1.0 #51084
Replies: 2 comments 1 reply
|
App |
1 reply
|
I like it really |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
@supabase/middleware 1.0.0 is stable: typed, composable middleware for fetch handlers. The engine runs wherever fetch runs, standalone or inside a framework through a short bridge you copy.
What's new
@supabase/middleware1.0.0 is on npm and JSR under thelatesttag. From 1.0 the package follows semantic versioning: breaking changes ship only in a new major.It is a small, MIT-licensed engine for per-request logic on Web Fetch handlers:
defineMiddlewarewrites one piece of per-request logic. It contributes one typed key to a sharedctx.pipeline([...], handler)runs several in order and returns the fetch handler. Middleware also nest directly, sopipelineis optional.Responseand stop the chain, or read and change the response on the way out.withCorsandwithFeatureFlag. Everything else is yours, or comes from a package.The engine runs wherever fetch runs: Supabase Edge Functions, Vercel Functions, Cloudflare Workers, Deno, Bun, and Node 22 or newer. Inside Hono, H3, Elysia, NestJS, or TanStack Start, the same middleware runs through a short, typechecked bridge you copy into your app. No adapter package, no new dependency. See the frameworks guide.
@supabase/serveris built on the engine and ships the Supabase middleware.withSupabase(config)with no handler is apipelineentry;withSupabase(config, handler)wraps a single handler. Entries before it in the array run ahead of the auth gate, and entries after it receive the Supabase context. The@supabase/server/middleware/*subpaths export the pieces on their own:withClaims,withRequiredClaims,withSupabaseClient,withSupabaseAdminClient,withPostgresClient, andwithPostgresAdminClient.withOAuthProtectedResourceanswers OAuth discovery for MCP clients. All of them are stable as of@supabase/server1.9.0.How to use it
On Edge Functions, import it directly. This example answers OAuth discovery for MCP clients, verifies the caller's token, and hands the handler a Supabase client scoped to that user. The Bring your own MCP guide builds a full MCP server on the same two entries:
Writing your own is one call:
The authoring guide covers prerequisites, the response seam, bundling several middleware into one, and publishing to npm and JSR.
Why we built this
Per-request logic is stuck where you wrote it. Move to a different runtime and you write it again. Adopt a framework and you rewrite it as that framework's middleware, which cannot leave that framework. Start a second project and you copy the file across. This is the code least worth rewriting: verifying a caller, scoping a database connection to them, handling CORS, checking a flag. It is fiddly, security-sensitive, and easy to get subtly wrong the second time.
@supabase/serverhas run on this engine since 1.5.1, released on August 31, 2026.withSupabaseis a composite of single-key parts: the auth gate, claims, CORS, the Supabase client, the admin client.withOAuthProtectedResourcehandles the whole OAuth protected-resource flow an MCP client expects, and it is one entry in the pipeline. None of it uses a private API. What you get is the same primitive we use.Affected products: Edge Functions, supabase-js, supabase-middleware, supabase-server
Authored by @mandarini
All reactions