Skip to content

Commit ac4f706

Browse files
fix: some refactor
1 parent a949d50 commit ac4f706

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

backend/src/auth/strategies/jwt.strategy.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ConfigService } from '@nestjs/config';
2-
import { Injectable, Logger } from '@nestjs/common';
2+
import { Injectable } from '@nestjs/common';
33
import { PassportStrategy } from '@nestjs/passport';
44

55
import { ExtractJwt, Strategy } from 'passport-jwt';
@@ -9,8 +9,6 @@ import { JwtPayload } from '../types';
99

1010
@Injectable()
1111
export class JwtStrategy extends PassportStrategy(Strategy) {
12-
private readonly logger = new Logger(JwtStrategy.name);
13-
1412
constructor(private readonly configService: ConfigService) {
1513
const secret = configService.getOrThrow<string>(JWT_ACCESS_TOKEN_SECRET);
1614
super({
@@ -21,7 +19,6 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
2119
}
2220

2321
async validate(payload: JwtPayload) {
24-
this.logger.log(`Validating JWT token: ${JSON.stringify(payload)}`);
2522
return { id: payload.sub, email: payload.email };
2623
}
2724
}

backend/src/workouts/workouts.controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ParseUUIDPipe,
99
Logger,
1010
UseGuards,
11+
UnauthorizedException,
1112
} from '@nestjs/common';
1213

1314
import { JwtAuthGuard } from '@src/auth/guards';
@@ -30,7 +31,7 @@ export class WorkoutsController {
3031
) {
3132
if (!userId) {
3233
this.logger.error(ResponseMessages.User.IdNotFound, userId);
33-
throw new Error(ResponseMessages.User.IdNotFound);
34+
throw new UnauthorizedException(ResponseMessages.User.IdNotFound);
3435
}
3536
return await this.workoutsService.create(CreateWorkoutDto, userId);
3637
}
@@ -40,7 +41,7 @@ export class WorkoutsController {
4041
async findAll(@CurrentUser('id') userId: string) {
4142
if (!userId) {
4243
this.logger.error(ResponseMessages.User.IdNotFound, userId);
43-
throw new Error(ResponseMessages.User.IdNotFound);
44+
throw new UnauthorizedException(ResponseMessages.User.IdNotFound);
4445
}
4546
return await this.workoutsService.findAll(userId);
4647
}

0 commit comments

Comments
 (0)