Skip to content

Commit

Permalink
fix: when user invlidated one token other tokens still be alive
Browse files Browse the repository at this point in the history
  • Loading branch information
Aish1990 committed May 31, 2024
1 parent 4bd6574 commit 9f2bff4
Show file tree
Hide file tree
Showing 3 changed files with 6 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
4 changes: 2 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,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(
Expand Down

0 comments on commit 9f2bff4

Please sign in to comment.