Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
21 lines
715 B
TypeScript
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);
|
|
}
|
|
}
|