From 9f2bff45ab43ebaa20072a644049eb3682fd5d41 Mon Sep 17 00:00:00 2001 From: Aish1990 Date: Fri, 31 May 2024 12:20:49 +0530 Subject: [PATCH 1/2] fix: when user invlidated one token other tokens still be alive --- apps/drec-api/src/auth/auth.controller.ts | 3 ++- apps/drec-api/src/auth/auth.service.ts | 4 ++-- apps/drec-api/src/pods/user/user.service.ts | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/drec-api/src/auth/auth.controller.ts b/apps/drec-api/src/auth/auth.controller.ts index adc582b78..296c3b627 100755 --- a/apps/drec-api/src/auth/auth.controller.ts +++ b/apps/drec-api/src/auth/auth.controller.ts @@ -43,7 +43,8 @@ export class AuthController { @HttpCode(HttpStatus.OK) async logout(@Request() req: ExpressRequest) { this.logger.verbose('Within login'); - await this.authService.logout(req.user as Omit); + const token: string = req.headers.authorization?.split(' ')[1]; + await this.authService.logout(req.user as Omit, token); return { message: 'Logout successful' }; } diff --git a/apps/drec-api/src/auth/auth.service.ts b/apps/drec-api/src/auth/auth.service.ts index 9c7c53fde..7c740e058 100755 --- a/apps/drec-api/src/auth/auth.service.ts +++ b/apps/drec-api/src/auth/auth.service.ts @@ -53,8 +53,8 @@ export class AuthService { accessToken: token, }; } - async logout(payload: IJWTPayload) { - return await this.userService.removeUsersession(payload.id); + async logout(payload: IJWTPayload, token: string) { + return await this.userService.removeUsersession(payload.id, token); } async isTokenBlacklisted( diff --git a/apps/drec-api/src/pods/user/user.service.ts b/apps/drec-api/src/pods/user/user.service.ts index d37c2d1db..80b944c53 100755 --- a/apps/drec-api/src/pods/user/user.service.ts +++ b/apps/drec-api/src/pods/user/user.service.ts @@ -725,8 +725,8 @@ export class UserService { * @param userId * @returns */ - async removeUsersession(userId: number) { - return await this.userloginSessionRepository.delete({ userId: userId }); + async removeUsersession(userId: number, token: string) { + return await this.userloginSessionRepository.delete({ userId: userId , accesstoken_hash: token.trim()}); } async hasgetUserTokenvalid( From 7ee0df3274df2c8237451923fe3433a22f2a4750 Mon Sep 17 00:00:00 2001 From: Aish1990 Date: Fri, 31 May 2024 12:28:54 +0530 Subject: [PATCH 2/2] Prettier fix --- apps/drec-api/src/pods/user/user.service.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/drec-api/src/pods/user/user.service.ts b/apps/drec-api/src/pods/user/user.service.ts index 80b944c53..3b3072b2c 100755 --- a/apps/drec-api/src/pods/user/user.service.ts +++ b/apps/drec-api/src/pods/user/user.service.ts @@ -726,7 +726,10 @@ export class UserService { * @returns */ async removeUsersession(userId: number, token: string) { - return await this.userloginSessionRepository.delete({ userId: userId , accesstoken_hash: token.trim()}); + return await this.userloginSessionRepository.delete({ + userId: userId, + accesstoken_hash: token.trim(), + }); } async hasgetUserTokenvalid(