Skip to content

Commit

Permalink
Merge pull request #81 from jihwooon/issue-52
Browse files Browse the repository at this point in the history
입력 받은 패스워드와 저장 된 패스워드를 비교하는 메서드를 리팩터링을 하라
  • Loading branch information
jihwooon authored Sep 30, 2023
2 parents 72cfddd + 7abbab2 commit bfc834c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions server/src/auth/signin/application/signin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export class SigninService {
private readonly tokenIssuer: TokenIssuer,
) {}

async login(email: string, password: string): Promise<Authentication> {
async login(email: string, rawPassword: string): Promise<Authentication> {
const member = await this.memberRepository.findByEmail(email)
if (!member) {
throw new MemberNotFoundException('회원 정보를 찾을 수 없습니다')
}

const isPasswordMatch = await this.passwordProvider.comparePassword(password, member)
const isPasswordMatch = await this.passwordProvider.comparePassword(rawPassword, member.password)
if (!isPasswordMatch) {
throw new BadRequestException('패스워드가 일치 하지 않습니다')
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/members/application/password.provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ describe('PasswordProvider class', () => {
describe('comparePassword method', () => {
context('입력 받은 패스워드와 저장된 패스워드가 일치하면', () => {
it('true를 리턴 해야 한다', async () => {
const hashedPassword = await passwordProvider.comparePassword(RAW_PASSWORD, userMock())
const hashedPassword = await passwordProvider.comparePassword(RAW_PASSWORD, userMock().password)

expect(hashedPassword).toEqual(true)
})
})
context('입력 받은 패스워드와 저장된 패스워드가 일치하지 않으면', () => {
it('false를 리턴 해야 한다', async () => {
const hashedPassword = await passwordProvider.comparePassword(FAIL_PASSWORD, userMock())
const hashedPassword = await passwordProvider.comparePassword(FAIL_PASSWORD, userMock().password)

expect(hashedPassword).toEqual(false)
})
Expand Down
8 changes: 3 additions & 5 deletions server/src/members/application/password.provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Injectable } from '@nestjs/common'
import { BadRequestException, Injectable } from '@nestjs/common'
import * as bcrypt from 'bcrypt'
import { BadRequestException } from '@nestjs/common'
import { Member } from '../domain/member.entity'

@Injectable()
export class PasswordProvider {
Expand All @@ -15,7 +13,7 @@ export class PasswordProvider {
return hashedPassword
}

async comparePassword(password: string, member: Member): Promise<boolean> {
return bcrypt.compare(password, member.password)
async comparePassword(rawPassword: string, password: string): Promise<boolean> {
return bcrypt.compare(rawPassword, password)
}
}

0 comments on commit bfc834c

Please sign in to comment.