diff --git a/backend/src/auth/auth.service.ts b/backend/src/auth/auth.service.ts index 4e775715..770f45f1 100644 --- a/backend/src/auth/auth.service.ts +++ b/backend/src/auth/auth.service.ts @@ -36,7 +36,7 @@ export class AuthService { } async validateUser(email: string, password: string): Promise> { - const user = await this.usersService.findOne(email); + const user = await this.usersService.findUserByEmail(email); if (!user || !bcrypt.compareSync(password, user.password)) { throw new ValidationException('로그인 실패'); } @@ -47,7 +47,7 @@ export class AuthService { } async refreshJWT(userId: string): Promise> { - const user = await this.usersService.getUserById(userId); + const user = await this.usersService.findUserById(userId); if (!user) { throw new HttpException('유효하지 않은 refreshToken', HttpStatus.BAD_REQUEST); } diff --git a/backend/src/user/user.service.ts b/backend/src/user/user.service.ts index 08ae0ba7..88ea4586 100644 --- a/backend/src/user/user.service.ts +++ b/backend/src/user/user.service.ts @@ -38,12 +38,12 @@ export class UsersService { } } - async findOne(email: string): Promise { + async findUserByEmail(email: string): Promise { const user = await this.usersRepository.findOne({ where: { email } }); return user; } - async getUserById(userId: string): Promise { + async findUserById(userId: string): Promise { return await this.usersRepository.findOne({ where: { id: userId } }); } @@ -65,30 +65,32 @@ export class UsersService { } async sendVerificationEmail(email: string) { - await this.findUserByEmail(email); + const user = await this.findUserByEmail(email); + if (!user) { + throw new HttpException('해당 이메일의 사용자를 찾을 수 없습니다.', HttpStatus.NOT_FOUND); + } await this.mailService.sendVerficationCode(email); } async checkEmailVarifacted(email: string) { const user = await this.findUserByEmail(email); + if (!user) { + throw new HttpException('해당 이메일의 사용자를 찾을 수 없습니다.', HttpStatus.NOT_FOUND); + } if (!user.verified) { return false; } return true; } + async changePassword(email: string, password: string) { const user = await this.findUserByEmail(email); + if (!user) { + throw new ValidationException('비밀번호 변경 실패'); + } const salt = await bcrypt.genSalt(); const hashedPassword = await bcrypt.hash(password, salt); user.password = hashedPassword; await this.usersRepository.save(user); } - - async findUserByEmail(email: string) { - const user = await this.usersRepository.findOne({ where: { email } }); - if (!user) { - throw new HttpException('해당 이메일을 찾을 수 없습니다.', HttpStatus.NOT_FOUND); - } - return user; - } }