Skip to content

feat: add NestJS adapter#55

Open
bogdantarasenko wants to merge 1 commit intosupabase:mainfrom
bogdantarasenko:feat/nestjs-adapter
Open

feat: add NestJS adapter#55
bogdantarasenko wants to merge 1 commit intosupabase:mainfrom
bogdantarasenko:feat/nestjs-adapter

Conversation

@bogdantarasenko
Copy link
Copy Markdown

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() or app.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 full SupabaseContext or a single field, with NestJS pipes applied to the extracted value.
  • Failed auth surfaces as HttpException with { message, code }; the underlying AuthError is exposed on cause so consumers can build their own exception filters.

@nestjs/common is 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 source
  • src/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 @SupabaseCtx with pipes)
  • vitest.config.ts — uses unplugin-swc so the integration tests get emitDecoratorMetadata, which Nest's DI requires (esbuild, vitest's default transform, doesn't emit it)
  • tsconfig.jsonexperimentalDecorators + emitDecoratorMetadata for the same reason
  • tsdown.config.ts, package.json exports, jsr.json — wire the new entry point
  • README.md, src/adapters/README.md, new docs/adapters/nestjs.md — documentation

Test plan

  • pnpm test — unit + integration tests pass on Express and Fastify
  • pnpm buildtsdown emits dist/adapters/nestjs/index.{mjs,cjs,d.mts,d.cts}
  • Reviewer: confirm the optional-peer-dep approach (peerDependenciesMeta) is acceptable so non-Nest users aren't affected
  • Reviewer: sanity-check the vitest.config.ts + unplugin-swc test setup; it's only needed because Nest's DI requires decorator metadata that esbuild doesn't emit

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant