Files
stack/apps/gateway/src/auth/auth.controller.ts
2026-03-13 02:37:56 +00:00

21 lines
715 B
TypeScript

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<void>;
constructor(@Inject(AUTH) auth: Auth) {
this.handler = toNodeHandler(auth);
}
@All('*path')
async handleAuth(@Req() req: FastifyRequest, @Res() res: FastifyReply): Promise<void> {
await this.handler(req.raw, res.raw);
}
}