25 lines
745 B
TypeScript
25 lines
745 B
TypeScript
import { Body, Controller, Post, Req } from '@nestjs/common';
|
|
|
|
import { AdminAuthService } from './admin-auth.service';
|
|
import { Public } from './decorators/admin-auth.decorators';
|
|
import { AdminLoginDto } from './dto';
|
|
|
|
@Controller('auth/admin')
|
|
export class AdminAuthController {
|
|
constructor(private readonly adminAuthService: AdminAuthService) {}
|
|
|
|
@Public()
|
|
@Post('login')
|
|
login(
|
|
@Body() body: AdminLoginDto,
|
|
@Req() request: { ip?: string; headers: Record<string, string | string[] | undefined> },
|
|
) {
|
|
const userAgent = request.headers['user-agent'];
|
|
|
|
return this.adminAuthService.login(body, {
|
|
ipAddress: request.ip,
|
|
userAgent: Array.isArray(userAgent) ? userAgent.join(', ') : userAgent,
|
|
});
|
|
}
|
|
}
|