From efb433ac47ad5577df63845cb43de5ba20899d87 Mon Sep 17 00:00:00 2001 From: younha00 Date: Thu, 27 Jun 2024 17:53:42 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9E=96=20[#2]Del:=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B2=84=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 - src/auth/auth.controller.ts | 31 +++++++------------- src/auth/guard/naver-auth-guard.ts | 23 --------------- src/auth/strategy/naver.strategy.ts | 44 ----------------------------- 4 files changed, 10 insertions(+), 89 deletions(-) delete mode 100644 src/auth/guard/naver-auth-guard.ts delete mode 100644 src/auth/strategy/naver.strategy.ts diff --git a/package.json b/package.json index b3b3996..554ce43 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "passport": "^0.7.0", "passport-jwt": "^4.0.1", "passport-local": "^1.0.0", - "passport-naver-v2": "^2.0.8", "pg": "^8.12.0", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1", diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index f8392b1..eea319f 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -1,8 +1,7 @@ - import { Body, Controller, Post, Headers, UseGuards } from '@nestjs/common'; import { AuthService } from './auth.service'; import { BasicTokenGuard } from './guard/basic-token.guard'; -import { AccessTokenGuard, RefreshTokenGuard } from './guard/bearer-token.guard'; +import { RefreshTokenGuard } from './guard/bearer-token.guard'; import { RegisterUserDto } from './dto/register-user.dto'; @Controller('auth') @@ -11,40 +10,34 @@ export class AuthController { @Post('token/access') @UseGuards(RefreshTokenGuard) - postTokenAccess( - @Headers('authorization') rawToken: string, - ){ + postTokenAccess(@Headers('authorization') rawToken: string) { const token = this.authService.extractTokenFromHeader(rawToken, true); - const newToken = this.authService.rotateToken(token, false,); + const newToken = this.authService.rotateToken(token, false); /** * {accessToken: {token}} */ return { accessToken: newToken, - } + }; } @Post('token/refresh') @UseGuards(RefreshTokenGuard) - postTokenRefresh( - @Headers('authorization') rawToken: string, - ){ + postTokenRefresh(@Headers('authorization') rawToken: string) { const token = this.authService.extractTokenFromHeader(rawToken, true); - const newToken = this.authService.rotateToken(token, true,); + const newToken = this.authService.rotateToken(token, true); /** * {refreshToken: {token}} */ return { refreshToken: newToken, - } + }; } // 로그인 @Post('login/email') @UseGuards(BasicTokenGuard) - postLoginEmail( - @Headers('authorization') rawToken: string, - ) { + postLoginEmail(@Headers('authorization') rawToken: string) { const token = this.authService.extractTokenFromHeader(rawToken, false); const credentials = this.authService.decodeBasicToken(token); @@ -53,11 +46,7 @@ export class AuthController { // 회원가입 @Post('register/email') - postRegisterEmail( - @Body() body: RegisterUserDto, - ) { - return this.authService.registerWithEmail( - body, - ); + postRegisterEmail(@Body() body: RegisterUserDto) { + return this.authService.registerWithEmail(body); } } diff --git a/src/auth/guard/naver-auth-guard.ts b/src/auth/guard/naver-auth-guard.ts deleted file mode 100644 index 2105892..0000000 --- a/src/auth/guard/naver-auth-guard.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ExecutionContext, Injectable } from '@nestjs/common'; -import { AuthGuard } from '@nestjs/passport'; - -@Injectable() -export class NaverAuthGuard extends AuthGuard('naver') { - constructor() { - super(); - } - - handleRequest( - err: any, - user: any, - info: any, - context: ExecutionContext, - status?: any, - ): TUser { - //에러가 존재하면 에러 처리로 넘긴다. - if (err || !user) { - throw err; - } - return user; - } -} diff --git a/src/auth/strategy/naver.strategy.ts b/src/auth/strategy/naver.strategy.ts deleted file mode 100644 index 01dd7fd..0000000 --- a/src/auth/strategy/naver.strategy.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; -import { PassportStrategy } from '@nestjs/passport'; -import { Strategy } from 'passport-naver-v2'; -import { AuthService } from '../auth.service'; -import { JwtService } from '@nestjs/jwt'; -import { - ENV_NAVER_CALLBACK_URL_KEY, - ENV_NAVER_CLIENT_ID_KEY, - ENV_NAVER_CLIENT_SECRET_KEY, -} from '../../common/const/env-keys.const'; - -@Injectable() -export class JwtNaverStrategy extends PassportStrategy(Strategy, 'naver') { - constructor( - private authService: AuthService, - private jwtService: JwtService, - private readonly configService: ConfigService, - ) { - super({ - clientID: configService.get(ENV_NAVER_CLIENT_ID_KEY), - clientSecret: configService.get(ENV_NAVER_CLIENT_SECRET_KEY), - callbackURL: configService.get(ENV_NAVER_CALLBACK_URL_KEY), - }); - } - - async validate( - accessToken: string, - refreshToken: string, - profile: any, - ): Promise { - console.log(profile); - const id = profile.id; - const email = profile.email; - const name = profile.name; - const user = { - id, - email, - name, - }; - - return user; - } -}