import { Body, Controller, Post, UnauthorizedException } from '@nestjs/common'; import { AuthClientService } from 'src/clients/auth/client.service'; import { ISignIn, IRefreshAccessToken } from 'src/clients/auth/interfaces'; @Controller('auth') export class AuthController { constructor(private authClient: AuthClientService) {} // DEPRECADO! @Post() async signIn_old(@Body() body: ISignIn) { console.log(`/auth`, 'SignIn_old'); return this.signIn(body); } @Post('login') async signIn(@Body() { username, password, totp }: ISignIn) { console.log(`/auth`, 'SignIn'); const tokens = await this.authClient .signIn({ username, password, totp }) .then((result) => result) .catch((err) => { throw new UnauthorizedException(err.message); }); return tokens; } @Post('refresh-access-token') async refreshAccessToken(@Body() { username, refreshToken }: IRefreshAccessToken) { console.log(`/auth`, 'RefreshAccessToken'); const accessToken = await this.authClient .refreshAccessToken({ username, refreshToken }) .then((result) => result) .catch((err) => { throw new UnauthorizedException(err.message); }); return accessToken; } }