Skip to content

Commit

Permalink
🔨 fix(user) : 유저 정보 조회시 없으면 401 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
ImNM committed Aug 15, 2022
1 parent a002589 commit 056a137
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
8 changes: 1 addition & 7 deletions src/auth/guards/AccessToken.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ export class AccessTokenGuard implements CanActivate {
]);

const payload = this.authService.verifyAccessJWT(jwtString);
const existCheck = await this.authService.checkUserExist(payload.id);
if (!existCheck) {
throw new UnauthorizedException(
AuthErrorDefine['Auth-1004'],
'디비에서 유저 조회시에 발생하는 오류'
);
}

// const user = payload
const user = payload;
const newObj: any = request;
Expand Down
7 changes: 3 additions & 4 deletions src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import { ResponseRandomCommentDto } from './dtos/RandomComment.response.dto';
import { UserFindDto } from './dtos/UserFind.dto';
import { ResponseCommentNumDto } from './dtos/CommentNum.response.dto';
import { ResponseRandomCommentUserDto } from './dtos/RandomCommentUser.response.dto';
import { ErrorResponse } from 'src/common/decorators/ErrorResponse.decorator';
import { AuthErrorDefine } from 'src/auth/Errors/AuthErrorDefine';

@ApiTags('users')
@ApiBearerAuth('accessToken')
Expand All @@ -53,10 +55,7 @@ export class UsersController {
description: '요청 성공시',
type: UserProfileDto
})
@ApiUnauthorizedResponse({
status: 401,
description: 'AccessToken이 없을 경우'
})
@ErrorResponse(HttpStatus.UNAUTHORIZED, [AuthErrorDefine['Auth-1003']])
@Get('')
async getMyUserInfo(@ReqUser() user: User) {
// findOneByUserId
Expand Down
13 changes: 11 additions & 2 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Logger } from '@nestjs/common';
import { Injectable, Logger, UnauthorizedException } from '@nestjs/common';
import { User } from 'src/database/entities/user.entity';
import { UserRepository } from 'src/database/repositories/user.repository';
import { RequestUserNameDto } from './dtos/UserName.request.dto';
Expand All @@ -14,6 +14,7 @@ import { ScrollOptionsDto } from './dtos/Scroll/ScrollOptions.dto';
import { ResponseScrollCommentsDto } from './dtos/Scroll/ScrollComments.response.dto';
import { RequestRandomCommentDto } from './dtos/RandomComment.request.dto';
import { UserFindDto } from './dtos/UserFind.dto';
import { AuthErrorDefine } from 'src/auth/Errors/AuthErrorDefine';

@Injectable()
export class UsersService {
Expand All @@ -29,6 +30,12 @@ export class UsersService {
async getMyInfo(user: User) {
Logger.log(user);
const myInfo = await this.userRepository.getMyInfo(user);
if (!myInfo) {
throw new UnauthorizedException(
AuthErrorDefine['Auth-1003'],
'디비에서 유저 조회시에 발생하는 오류'
);
}
return plainToInstance(UserProfileDto, myInfo);
}

Expand Down Expand Up @@ -108,7 +115,9 @@ export class UsersService {

// 댓글 랜덤 조회(유저 정보 포함)
async getRandomCommentUser(requestRandomCommentDto: RequestRandomCommentDto) {
return await this.commentRepository.getRandomCommentUser(requestRandomCommentDto);
return await this.commentRepository.getRandomCommentUser(
requestRandomCommentDto
);
}

// 댓글 삭제
Expand Down

0 comments on commit 056a137

Please sign in to comment.