import { Body, Controller, HttpCode, Inject, Post, Req, forwardRef } from '@nestjs/common' import type { FastifyRequest } from 'fastify' import { Public } from '../common/decorators/public.decorator' import { getClientIp } from '../common/http/client-ip' import { assertAuthRateLimit } from '../common/rate-limit/auth-rate-limit' import { strictBodyPipe } from '../common/pipes/strict-body.pipe' import { AuthService } from './auth.service' import { LoginDto } from './dto/login.dto' import { RegisterDto } from './dto/register.dto' @Controller('api/auth') export class AuthController { constructor(@Inject(forwardRef(() => AuthService)) private readonly auth: AuthService) {} @Public() @HttpCode(200) @Post('register') register(@Req() req: FastifyRequest, @Body(strictBodyPipe(RegisterDto)) dto: RegisterDto) { assertAuthRateLimit(getClientIp(req)) return this.auth.register(dto.username, dto.password, dto.name) } @Public() @HttpCode(200) @Post('login') login(@Req() req: FastifyRequest, @Body(strictBodyPipe(LoginDto)) dto: LoginDto) { assertAuthRateLimit(getClientIp(req)) return this.auth.login(dto.username, dto.password) } }