import type { IncomingMessage, ServerResponse } from 'node:http'; import { All, Controller, Inject, Req, Res } from '@nestjs/common'; import type { FastifyReply, FastifyRequest } from 'fastify'; import { toNodeHandler } from 'better-auth/node'; import type { Auth } from '@mosaic/auth'; import { AUTH } from './auth.module.js'; @Controller('api/auth') export class AuthController { private readonly handler: (req: IncomingMessage, res: ServerResponse) => Promise; constructor(@Inject(AUTH) auth: Auth) { this.handler = toNodeHandler(auth); } @All('*path') async handleAuth(@Req() req: FastifyRequest, @Res() res: FastifyReply): Promise { await this.handler(req.raw, res.raw); } }