This repository has been archived on 2025-03-21. You can view files and clone it, but cannot push or open issues or pull requests.
insiemesalute-3p-nx/apps/ebitemp-api/src/modules/auth/auth.controller.ts

32 lines
1.1 KiB
TypeScript

import { Body, Controller, HttpCode, HttpStatus, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth } from '@nestjs/swagger';
import { AccountsEntity } from '../database/connections/ebitemp-api/entities';
import { LoginDto, LoginResDto } from './auth.dto';
import { AuthService } from './auth.service';
import { AuthenticatedUser } from './authenticated-user.decorator';
import { Public } from './strategies/jwt/jwt-auth.guard';
import { JwtRefreshGuard } from './strategies/jwt/jwt-refresh.guard';
@ApiBearerAuth()
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@HttpCode(HttpStatus.OK)
@Public()
@Post('login')
async logIn(@Body() body: LoginDto): Promise<LoginResDto> {
const { username, password } = body;
const user = await this.authService.getAuthenticatedUser(username, password);
return await this.authService.signJwts(user);
}
@HttpCode(HttpStatus.OK)
@UseGuards(JwtRefreshGuard)
@Public(true)
@Post('refresh')
async refresh(@AuthenticatedUser() user: AccountsEntity): Promise<LoginResDto> {
return await this.authService.signJwts(user);
}
}