feat: add NestJS adapter#55
Open
bogdantarasenko wants to merge 1 commit intosupabase:mainfrom
Open
Conversation
Ships `@supabase/server/adapters/nestjs`:
- `withSupabase(opts)` — class guard for `@UseGuards()` and
`useGlobalGuards()`, supporting Express and Fastify
- `@SupabaseCtx(key?, ...pipes)` — param decorator returning the full
SupabaseContext or a single field, with NestJS pipes applied to the
extracted value
- 401s thrown as `HttpException` with `{ message, code }`; the
underlying `AuthError` is exposed on `cause`
Adds `@nestjs/common` as an optional peer dep (`^10 || ^11`), wires the
new export in package.json / jsr.json / tsdown.config.ts, and enables
`experimentalDecorators` + `emitDecoratorMetadata` in tsconfig. Test
setup uses unplugin-swc via vitest.config.ts so integration tests can
boot a real Nest app on both Express and Fastify.
Docs: README quickstart + docs/adapters/nestjs.md.
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 NestJS adapter under
@supabase/server/adapters/nestjs, alongside the existing Hono and H3 adapters.withSupabase(opts)returns a class guard usable with@UseGuards()orapp.useGlobalGuards(new (withSupabase(...))()). Works on both Express and Fastify platforms; HTTP/2 pseudo-headers and non-HTTP execution contexts (rpc/ws) are handled.@SupabaseCtx(key?, ...pipes)is a param decorator that returns the fullSupabaseContextor a single field, with NestJS pipes applied to the extracted value.HttpExceptionwith{ message, code }; the underlyingAuthErroris exposed oncauseso consumers can build their own exception filters.@nestjs/commonis added as an optional peer dep (^10.0.0 || ^11.0.0), so users who don't import the adapter aren't forced to install Nest.What's in the diff
src/adapters/nestjs/{middleware,decorator,index}.ts— adapter sourcesrc/adapters/nestjs/{middleware,integration}.test.ts— unit tests for the guard/decorator plus integration tests that boot a real Nest app on Express and Fastify (covers@UseGuards,useGlobalGuards, and@SupabaseCtxwith pipes)vitest.config.ts— usesunplugin-swcso the integration tests getemitDecoratorMetadata, which Nest's DI requires (esbuild, vitest's default transform, doesn't emit it)tsconfig.json—experimentalDecorators+emitDecoratorMetadatafor the same reasontsdown.config.ts,package.jsonexports,jsr.json— wire the new entry pointREADME.md,src/adapters/README.md, newdocs/adapters/nestjs.md— documentationTest plan
pnpm test— unit + integration tests pass on Express and Fastifypnpm build—tsdownemitsdist/adapters/nestjs/index.{mjs,cjs,d.mts,d.cts}peerDependenciesMeta) is acceptable so non-Nest users aren't affectedvitest.config.ts+unplugin-swctest setup; it's only needed because Nest's DI requires decorator metadata that esbuild doesn't emit