From 3d83b897cec2492da0c0902b8a7a4b86fe31abf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Mon, 12 Sep 2022 14:59:33 +0900 Subject: [PATCH] nestjs_auth... --- src/auth/auth.service.ts | 6 +++--- src/auth/guards/local.strategy.ts | 3 ++- src/user/user.service.ts | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index c1b0876..4e3e6ed 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -19,7 +19,7 @@ export class AuthService { // return await bcrypt // .hash(password, jwtConstants.password_saltorRounds) // .catch((e) => { - // new Error('암호화 실패' + e) + // throw new Error('암호화 실패' + e) // }) return password } @@ -28,7 +28,7 @@ export class AuthService { const user = await this.userService .fetchOne({ email: email }) .catch((error) => { - new UnauthorizedException('사용자를 찾을 수 없습니다.' + error) + throw new UnauthorizedException('사용자를 찾을 수 없습니다.' + error) }) const encryptedPassword = await this.getEcryptedPassword(password) if (user && user.password === encryptedPassword) { @@ -36,7 +36,7 @@ export class AuthService { const { password, ...result } = user return result } else { - new UnauthorizedException('암호가 맞지 않습니다.') + throw new UnauthorizedException('암호가 맞지 않습니다.') } } diff --git a/src/auth/guards/local.strategy.ts b/src/auth/guards/local.strategy.ts index 4325973..2cf561c 100644 --- a/src/auth/guards/local.strategy.ts +++ b/src/auth/guards/local.strategy.ts @@ -17,7 +17,8 @@ export class LocalStrategy extends PassportStrategy(Strategy) { try { return await this.authService.validateUser(email, password) } catch (e) { - new UnauthorizedException(e.message) + console.log(e) + throw new UnauthorizedException(e.message) } } } diff --git a/src/user/user.service.ts b/src/user/user.service.ts index c695715..4c432ba 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -43,7 +43,7 @@ export class UserService { } //단일 조회 - async fetchOne(where: Prisma.UserWhereInput): Promise { + async fetchOne(where: Prisma.UserWhereInput): Promise { return await this.prisma.user.findFirstOrThrow({ where: where }) } @@ -56,7 +56,7 @@ export class UserService { async update(params: { where: Prisma.UserWhereUniqueInput data: Prisma.UserUpdateInput - }): Promise { + }): Promise { const { where, data } = params return await this.prisma.user.update({ data, @@ -65,7 +65,7 @@ export class UserService { } //단일 삭제 - async remove(where: Prisma.UserWhereUniqueInput): Promise { + async remove(where: Prisma.UserWhereUniqueInput) { return await this.prisma.user.delete({ where }) } }