Skip to content

Commit

Permalink
Merge pull request #277 from d-rec/DR-815
Browse files Browse the repository at this point in the history
fix: when user invlidated one token other tokens still be alive
  • Loading branch information
Aish1990 authored May 31, 2024
2 parents 4bd6574 + 7ee0df3 commit 311b2cc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion apps/drec-api/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IUser, 'password'>);
const token: string = req.headers.authorization?.split(' ')[1];
await this.authService.logout(req.user as Omit<IUser, 'password'>, token);
return { message: 'Logout successful' };
}

Expand Down
4 changes: 2 additions & 2 deletions apps/drec-api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check warning on line 56 in apps/drec-api/src/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Missing return type on function
return await this.userService.removeUsersession(payload.id, token);
}

async isTokenBlacklisted(
Expand Down
7 changes: 5 additions & 2 deletions apps/drec-api/src/pods/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,11 @@ 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(
Expand Down

0 comments on commit 311b2cc

Please sign in to comment.