feat: add Express 5 adapter#66
Open
bogdantarasenko wants to merge 1 commit into
Open
Conversation
Member
|
Please remove this |
56255d3 to
9d3d5e3
Compare
Adds @supabase/server/adapters/express targeting Express 5, mirroring the Hono/H3 adapter contract. Public surface: withSupabase() middleware, requireAuth() guard, withSupabaseRoute() per-route wrapper, and the WithSupabaseExpressConfig type. Resolved context lives on res.locals.supabaseContext via Express.Locals declaration merging. Auth errors flow through a configurable onError option (default: next(error), Express-idiomatic). The Express req to Fetch Request bridge preserves headers including multi-value Set-Cookie and Cookie, composes absolute URLs under trust proxy, and forwards bodies for non-GET/HEAD methods. No new runtime deps; express ^5.0.0 is an optional peer.
9d3d5e3 to
a4bf2f1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a community Express 5 adapter under
@supabase/server/adapters/express, alongside the existing Hono, H3, and Elysia adapters.withSupabase(config)returns a standard Express middleware. Resolved context lives onres.locals.supabaseContextviaExpress.Localsdeclaration merging, so downstream handlers and middleware get full type inference.requireAuth(...modes)is a per-route guard that asserts the context is set and (optionally) thatauthModematches one of the listed modes. Useful when one app mixes routes with different auth requirements.withSupabaseRoute(config, handler)is a per-route wrapper for cases where global middleware doesn't fit — same context shape, async errors are forwarded tonext().onErroroption. Default isnext(error)(Express-idiomatic); pass a function to send a custom response instead.req→ FetchRequestbridge preserves headers (incl. multi-valueSet-Cookie/Cookie), composes absolute URLs underapp.set('trust proxy', true), and forwards bodies for non-GET/HEAD methods.expressis added as an optional peer dep (^5.0.0), so users who don't import the adapter aren't forced to install Express. No new runtime dependencies.What's in the diff
src/adapters/express/{middleware,require-auth,with-supabase-route,to-fetch-request,index}.ts— adapter sourcesrc/adapters/express/*.test.ts— unit tests covering everyAuthMode(user/publishable/secret/none), the array form, invalid-JWT / missing-credential failures, theres.locals.supabaseContextshort-circuit path, default and customonError, therequireAuth()guard (present / missing context / mode mismatch), thewithSupabaseRoute()wrapper (success, auth failure, async-thrown errors), and thereq→Requestbridge (headers, body, trust-proxy URL composition)tsdown.config.ts,package.jsonexports +peerDependencies+peerDependenciesMeta+devDependencies,jsr.json— wire the new entry pointREADME.md,src/adapters/README.md, newdocs/adapters/express.md— documentationTest plan
pnpm installresolves the new peer/dev dependenciespnpm typecheckpnpm lintpnpm test— 190/190 pass, including all Express adapter test filespnpm buildproducesdist/adapters/express/index.{mjs,cjs,d.mts,d.cts}peerDependenciesMeta) is consistent with the other adaptersapp.set('trust proxy', true)behind a reverse proxy to confirm the bridged URL usesX-Forwarded-*