Skip to content

Commit

Permalink
Merge pull request #100 from LocalMingle/eric
Browse files Browse the repository at this point in the history
[완료] 동일한 패스워드 입력 시 에러 발생 로직 추가
  • Loading branch information
erickimme authored Oct 26, 2023
2 parents 39f4ff8 + 2e3f15b commit 62c91b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,17 @@ export class UsersController {
@ApiOperation({ summary: '비밀번호 변경' })
@ApiResponse({ status: 200, description: '비밀번호가 변경되었습니다' })
@ApiResponse({ status: 404, description: '유저 정보가 존재하지 않습니다' })
@ApiResponse({
status: 400,
description: '동일한 비밀번호를 입력하였습니다',
})
@UseGuards(JwtAccessAuthGuard)
@ApiBearerAuth()
async updatePassword(
@Req() req: RequestWithUser,
@Body() updateUserPasswordDto: UpdateUserPasswordDto
) {
const { userId } = req.user; // request에 user 객체가 추가되었고 userId에 값 할당
const { userId } = req.user;
await this.usersService.updatePassword(userId, updateUserPasswordDto);
return { message: '비밀번호가 변경되었습니다' };
}
Expand Down
8 changes: 7 additions & 1 deletion src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ export class UsersService {
where: { userId },
});
if (!user) {
throw new BadRequestException('유저 정보가 존재하지 않습니다.');
throw new BadRequestException('유저 정보가 존재하지 않습니다');
}

// 기존 현재 패스워드와 변경하려는 새로운 패스워드가 같은지 확인 후 같은 경우 에러
const isPasswordMatching = await bcrypt.compare(newPassword, user.password);
if (isPasswordMatching) {
throw new BadRequestException('동일한 비밀번호를 입력하였습니다');
}

// password 업데이트
Expand Down

0 comments on commit 62c91b5

Please sign in to comment.