From 9427680b5bde6e0899efb5eb00b7a69eb92b6971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Thu, 15 Sep 2022 17:26:51 +0900 Subject: [PATCH] nestjs_auth... --- src/auth/auth.controller.ts | 3 ++- src/auth/auth.service.ts | 8 ++------ src/auth/guards/local.strategy.ts | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 18ff5eb..365f79d 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -34,6 +34,7 @@ export class AuthController { //사용자 등록 @Post('register') async add(@Body() data: UserDTO) { - return await this.authService.register(data) + const user = await this.authService.register(data) + return await this.authService.login(user) } } diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 9a1a370..cb79120 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -25,11 +25,7 @@ export class AuthService { } //app.controller.ts에서 AuthGuard('local') 또는 AuthGuard('jwt')용 async validateUser(where: Prisma.UserWhereInput): Promise { - try { - await this.userService.fetchOne(where) - } catch (e) { - throw new UnauthorizedException('계정 확인이 되지 않습니다.') - } + return await this.userService.fetchOne(where) } async login(user: User): Promise { @@ -41,7 +37,7 @@ export class AuthService { async register(data: UserDTO): Promise { data.refresh_token = await this.getRefreshToken(data) data.password = await this.getEcryptedPassword(data.password) - return await this.login(await this.userService.add(data)) + return await this.userService.add(data) } //Access Token 재발행 diff --git a/src/auth/guards/local.strategy.ts b/src/auth/guards/local.strategy.ts index e48f834..fa7083a 100644 --- a/src/auth/guards/local.strategy.ts +++ b/src/auth/guards/local.strategy.ts @@ -23,7 +23,7 @@ export class LocalStrategy extends PassportStrategy(Strategy) { password: encryptedPassword }) } catch (e) { - throw new UnauthorizedException(e) + throw new UnauthorizedException('계정 확인이 되지 않습니다.') } } }