Skip to content

Update adapters to use AuthPlugin service for authentication#591

Merged
hotlong merged 3 commits intomainfrom
copilot/update-adapters-with-authplugin
Feb 10, 2026
Merged

Update adapters to use AuthPlugin service for authentication#591
hotlong merged 3 commits intomainfrom
copilot/update-adapters-with-authplugin

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 10, 2026

Adapters (Hono/Next.js/NestJS) bypassed the AuthPlugin service, routing auth through the deprecated HttpDispatcher.handleAuth(). This PR wires them to kernel.getService('auth') with graceful fallback.

Adapter changes

  • Hono: Forwards c.req.raw (Web Request) directly to authService.handleRequest()
  • Next.js: Forwards NextRequest to authService.handleRequest(), converts Web Response back to NextResponse
  • NestJS: Constructs Web Request from Express/Fastify req (URL, headers, body), forwards to authService.handleRequest(), pipes response back through res
  • All three fall back to dispatcher.handleAuth() when no auth service is registered
// New preferred path (all adapters)
const authService = typeof kernel.getService === 'function'
  ? kernel.getService('auth')
  : null;

if (authService && typeof authService.handleRequest === 'function') {
  return await authService.handleRequest(request);
}

// Legacy fallback
const result = await dispatcher.handleAuth(path, method, body, { request });

Tests

  • 12 new auth integration tests (4 per adapter): service usage, fallback, GET forwarding, error handling
  • All 84 tests pass (24 existing + 4 new per adapter)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack-play Ready Ready Preview, Comment Feb 10, 2026 2:52pm
spec Canceled Canceled Feb 10, 2026 2:52pm

Request Review

Copilot AI and others added 2 commits February 10, 2026 14:32
…patcher

- Hono: Try kernel.getService('auth') before dispatcher.handleAuth()
- Next.js: Try kernel.getService('auth') before dispatcher.handleAuth()
- NestJS: Try kernel.getService('auth') before dispatcher.handleAuth()
- Add 4 auth integration tests per adapter (12 total)

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
…e in NestJS adapter

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Update adapters to use AuthPlugin service Update adapters to use AuthPlugin service for authentication Feb 10, 2026
Copilot AI requested a review from hotlong February 10, 2026 14:37
@hotlong hotlong marked this pull request as ready for review February 10, 2026 14:37
Copilot AI review requested due to automatic review settings February 10, 2026 14:37
@hotlong hotlong merged commit 67b305d into main Feb 10, 2026
1 of 3 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Hono, Next.js, and NestJS adapters to route authentication through the AuthPlugin service (kernel.getService('auth').handleRequest(...)) when available, with a backward-compatible fallback to the deprecated HttpDispatcher.handleAuth() path.

Changes:

  • Add AuthPlugin-first routing in all three adapters, with dispatcher fallback.
  • Add new adapter-level integration tests validating service usage, fallback behavior, GET forwarding, and error handling.
  • Implement response/request bridging where needed (notably Next.js and NestJS) to adapt between framework request/response types and Web Request/Response.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/adapters/nextjs/src/index.ts Routes auth/* via AuthPlugin service first and converts Web Response to NextResponse.
packages/adapters/nextjs/src/nextjs.test.ts Adds tests covering AuthPlugin-service routing for the Next.js adapter.
packages/adapters/nestjs/src/index.ts Routes auth/* via AuthPlugin service first by constructing a Web Request and piping the Web Response back to Nest’s response.
packages/adapters/nestjs/src/nestjs.test.ts Adds tests covering AuthPlugin-service routing for the NestJS adapter.
packages/adapters/hono/src/index.ts Routes auth/* via AuthPlugin service first by forwarding c.req.raw directly.
packages/adapters/hono/src/hono.test.ts Adds tests covering AuthPlugin-service routing for the Hono adapter.

Comment on lines +71 to +75
// Convert Web Response to NextResponse
const body = await response.text();
const headers: Record<string, string> = {};
response.headers.forEach((v: string, k: string) => { headers[k] = v; });
return new NextResponse(body, { status: response.status, headers });
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting the Web Response to NextResponse via await response.text() and a Record<string,string> drops streaming bodies and cannot preserve multi-value headers (notably set-cookie, which auth flows commonly rely on). Prefer returning a NextResponse backed by response.body and forward headers using a Headers/HeadersInit that preserves duplicates.

Suggested change
// Convert Web Response to NextResponse
const body = await response.text();
const headers: Record<string, string> = {};
response.headers.forEach((v: string, k: string) => { headers[k] = v; });
return new NextResponse(body, { status: response.status, headers });
// Convert Web Response to NextResponse while preserving streaming body and multi-value headers
const headers = new Headers(response.headers);
return new NextResponse(response.body, {
status: response.status,
headers,
});

Copilot uses AI. Check for mistakes.
Comment on lines +137 to +141
// Convert Web Response to Express/Fastify response
res.status(response.status);
response.headers.forEach((v: string, k: string) => res.setHeader(k, v));
const text = await response.text();
return res.send(text);
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When piping the AuthPlugin Response back to res, using response.headers.forEach((v,k)=>res.setHeader(k,v)) plus await response.text() will (1) lose streaming/binary bodies and (2) mishandle multi-value headers like set-cookie (only one value survives / may be comma-joined depending on fetch impl). Consider forwarding response.body as a stream when available and ensure set-cookie is set as an array / appended per value.

Copilot uses AI. Check for mistakes.
Comment on lines +69 to +72
// Try AuthPlugin service first (preferred path)
const authService = typeof options.kernel.getService === 'function'
? options.kernel.getService('auth')
: null;
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same AuthPlugin-detection logic (checking kernel.getService('auth') and handleRequest) is now duplicated across adapters. To reduce drift, consider extracting a small shared helper (e.g., in @objectstack/runtime or a local adapters util) that returns an auth handler or null, and reuse it here.

Copilot uses AI. Check for mistakes.
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.

3 participants