251120:1700 Backend T3.4
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Controller, Post, Body, UnauthorizedException } from '@nestjs/common';
|
||||
import { Throttle } from '@nestjs/throttler'; // <--- ✅ เพิ่มบรรทัดนี้ครับ
|
||||
import { AuthService } from './auth.service.js';
|
||||
import { LoginDto } from './dto/login.dto.js'; // <--- Import DTO
|
||||
import { RegisterDto } from './dto/register.dto.js'; // <--- Import DTO
|
||||
@@ -8,6 +9,8 @@ export class AuthController {
|
||||
constructor(private authService: AuthService) {}
|
||||
|
||||
@Post('login')
|
||||
// เพิ่มความเข้มงวดให้ Login (กัน Brute Force)
|
||||
@Throttle({ default: { limit: 10, ttl: 60000 } }) // 🔒 ให้ลองได้แค่ 5 ครั้ง ใน 1 นาที
|
||||
// เปลี่ยน @Body() req เป็น @Body() loginDto: LoginDto
|
||||
async login(@Body() loginDto: LoginDto) {
|
||||
const user = await this.authService.validateUser(
|
||||
@@ -27,4 +30,11 @@ export class AuthController {
|
||||
async register(@Body() registerDto: RegisterDto) {
|
||||
return this.authService.register(registerDto);
|
||||
}
|
||||
/*ตัวอย่าง: ยกเว้นการนับ (เช่น Health Check)
|
||||
import { SkipThrottle } from '@nestjs/throttler';
|
||||
|
||||
@SkipThrottle()
|
||||
@Get('health')
|
||||
check() { ... }
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user