From 98759b1cf52d0f27482c3677990e2102c260ed2c Mon Sep 17 00:00:00 2001 From: Gabriel Rosa Date: Thu, 7 Dec 2023 17:27:30 -0300 Subject: [PATCH] FIX: logging oauth error --- src/authentication/authentication.guard.ts | 8 +++++--- src/modules/auth/auth.controller.ts | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/authentication/authentication.guard.ts b/src/authentication/authentication.guard.ts index 26e6d6b..2ea1747 100644 --- a/src/authentication/authentication.guard.ts +++ b/src/authentication/authentication.guard.ts @@ -79,11 +79,13 @@ export class AuthenticationGuard request, mustBeAuthenticated: boolean, ): RequestUser | false { - const accessToken = request.get('Authorization'); + const accessToken: string = request.get('Authorization'); let accessTokenPayload: RequestUser; - - this.logger.info(`accessToken: ${accessToken}`) + this.logger.info(`mustBeAuthenticated: ${mustBeAuthenticated}`); + this.logger.info( + `accessToken (first 5 chars): ${accessToken?.slice(0, 5)}`, + ); // If the user isn't authenticated, an error will occurr anywhere here. // Fancy error avoidance isn't performed by purpose, such as avoiding to access null values. try { diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts index 47b1a9a..980be61 100644 --- a/src/modules/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -327,7 +327,8 @@ export class AuthController { language = 'pt-br', } = await this.callback(req, 'magalu-id'); if (url.searchParams.get('error')) { - this.logger.error('/oauth/magalu-id - ERROR'); + this.logger.error('/oauth/magalu-id/callback - ERROR'); + this.logger.error(url.searchParams.get('error')); return { url: url.href }; } @@ -338,11 +339,11 @@ export class AuthController { refreshToken, }) .then(({ session }) => { - this.logger.info('/oauth/magalu-id - SUCESS'); + this.logger.info('/oauth/magalu-id/callback - SUCESS'); url.searchParams.set('session', session); }) .catch((err) => { - this.logger.error('/oauth/magalu-id - ERROR'); + this.logger.error('/oauth/magalu-id/callback - LOGIN ERROR'); let error = OauthErrors.INVALID_CREDENTIALS[language].error; let error_description = OauthErrors.INVALID_CREDENTIALS[language].error_description;