2026-10-12 14:35:42 +03:30
|
|
|
import { Body, Controller, HttpCode, Inject, Post, Req, forwardRef } from '@nestjs/common'
|
|
|
|
|
import type { FastifyRequest } from 'fastify'
|
2026-08-02 08:08:11 +02:00
|
|
|
import { Public } from '../common/decorators/public.decorator'
|
2026-10-12 14:35:42 +03:30
|
|
|
import { getClientIp } from '../common/http/client-ip'
|
|
|
|
|
import { assertAuthRateLimit } from '../common/rate-limit/auth-rate-limit'
|
2026-08-02 08:08:11 +02:00
|
|
|
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')
|
2026-10-12 14:35:42 +03:30
|
|
|
register(@Req() req: FastifyRequest, @Body(strictBodyPipe(RegisterDto)) dto: RegisterDto) {
|
|
|
|
|
assertAuthRateLimit(getClientIp(req))
|
2026-08-02 08:08:11 +02:00
|
|
|
return this.auth.register(dto.username, dto.password, dto.name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Public()
|
|
|
|
|
@HttpCode(200)
|
|
|
|
|
@Post('login')
|
2026-10-12 14:35:42 +03:30
|
|
|
login(@Req() req: FastifyRequest, @Body(strictBodyPipe(LoginDto)) dto: LoginDto) {
|
|
|
|
|
assertAuthRateLimit(getClientIp(req))
|
2026-08-02 08:08:11 +02:00
|
|
|
return this.auth.login(dto.username, dto.password)
|
|
|
|
|
}
|
|
|
|
|
}
|