From 7d14080ac1a0455e49b1d1056e26fb1eecb74b43 Mon Sep 17 00:00:00 2001 From: "rodrigo.zamboni" Date: Thu, 14 Apr 2022 14:48:40 -0300 Subject: [PATCH 1/2] FIX: Invalid auth credentials return --- src/middlewares/authentication.ts | 1 - src/modules/auth/auth.controller.ts | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/middlewares/authentication.ts b/src/middlewares/authentication.ts index 3a7a1f9..baf46f2 100644 --- a/src/middlewares/authentication.ts +++ b/src/middlewares/authentication.ts @@ -14,7 +14,6 @@ import { HttpExceptionFilter } from 'src/error/http-exception.filter'; @UseFilters(new HttpExceptionFilter()) export class LoggerMiddleware implements NestMiddleware { use = async (request: Request, response: Response, next: NextFunction) => { - console.log('Middle', new Date()); const idToken = request.get('Dadosfera-User'); const accessToken = request.get('Authorization'); const privateKey = process.env.JWT_PRIVATE_KEY; diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts index c58f248..f5cd851 100644 --- a/src/modules/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -1,4 +1,10 @@ -import { Body, Controller, Post } from '@nestjs/common'; +import { + Body, + Controller, + HttpException, + HttpStatus, + Post, +} from '@nestjs/common'; import { AuthClientService } from 'src/clients/auth/client.service'; @@ -18,7 +24,9 @@ export class AuthController { const tokens = await this.authClient .signIn({ username, password }) .then((result) => result) - .catch((err) => console.log(err)); + .catch((err) => { + throw new HttpException(err.message, HttpStatus.UNAUTHORIZED); + }); return tokens; } From ecdc7b4eb6ad2bb72bf46c6f958a359f2b1c5db2 Mon Sep 17 00:00:00 2001 From: "rodrigo.zamboni" Date: Thu, 14 Apr 2022 14:56:18 -0300 Subject: [PATCH 2/2] FIX: using Unauth nest function --- src/modules/auth/auth.controller.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts index f5cd851..ba13f88 100644 --- a/src/modules/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -1,10 +1,4 @@ -import { - Body, - Controller, - HttpException, - HttpStatus, - Post, -} from '@nestjs/common'; +import { Body, Controller, Post, UnauthorizedException } from '@nestjs/common'; import { AuthClientService } from 'src/clients/auth/client.service'; @@ -25,7 +19,7 @@ export class AuthController { .signIn({ username, password }) .then((result) => result) .catch((err) => { - throw new HttpException(err.message, HttpStatus.UNAUTHORIZED); + throw new UnauthorizedException(err.message); }); return tokens;