From 755a24d9f41f459b3db0105ea201eb983c4a0477 Mon Sep 17 00:00:00 2001 From: cabbage556 Date: Thu, 30 Mar 2023 21:41:04 +0900 Subject: [PATCH] =?UTF-8?q?release:=20=EB=B0=B0=ED=8F=AC=20=EB=B2=84?= =?UTF-8?q?=EC=A0=84=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 서버 배포 버전 - 1.6 cors 에러 수정 release --- cloudbuild.yaml | 2 +- docker-compose.prod.yaml | 2 +- src/apis/auth/auth.service.ts | 54 ++++++++++++----------------------- src/app.module.ts | 10 +++++++ src/main.ts | 3 +- 5 files changed, 32 insertions(+), 39 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 211978b..7e8d331 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -16,7 +16,7 @@ steps: - set - image - deployment/groomeong-backend - - backend-sha256-1=asia.gcr.io/project-groomeong/backend:1.5 + - backend-sha256-1=asia.gcr.io/project-groomeong/backend:1.6 env: - CLOUDSDK_COMPUTE_ZONE=asia-northeast3 - CLOUDSDK_CONTAINER_CLUSTER=autopilot-cluster-5 diff --git a/docker-compose.prod.yaml b/docker-compose.prod.yaml index 630d80e..e822bfd 100644 --- a/docker-compose.prod.yaml +++ b/docker-compose.prod.yaml @@ -2,7 +2,7 @@ version: '3.7' services: my-backend: - image: asia.gcr.io/project-groomeong/backend:1.5 + image: asia.gcr.io/project-groomeong/backend:1.6 platform: linux/x86_64 build: context: . diff --git a/src/apis/auth/auth.service.ts b/src/apis/auth/auth.service.ts index 731efd7..189cde2 100644 --- a/src/apis/auth/auth.service.ts +++ b/src/apis/auth/auth.service.ts @@ -23,7 +23,6 @@ import * as jwt from 'jsonwebtoken'; export class AuthService { constructor( private readonly usersService: UsersService, // - private readonly jwtService: JwtService, // @Inject(CACHE_MANAGER) @@ -37,15 +36,11 @@ export class AuthService { req, res, }: IAuthServiceLogin): Promise { - // 의존성주입한 usersService 에서 email 찾아오기 const user = await this.usersService.findOneByEmail({ email }); - - // 일치하는 유저가 없으면 에러던지기!! if (!user) { throw new UnprocessableEntityException('이메일이 일치하지 않습니다!!'); } - // 이메일은 일치하지만 비밀번호가 일치하지 않으면 에러던지기!! const isAuth = await bcrypt.compare(password, user.password); if (!isAuth) { throw new UnprocessableEntityException('비밀번호가 일치하지 않습니다!!'); @@ -59,18 +54,14 @@ export class AuthService { async logout({ req, res }: IAuthServiceLogOut) { try { - const accessToken = await req.headers['authorization'].replace( - 'Bearer ', - '', - ); - const refreshToken = await req.headers['cookie'].split( - 'refreshToken=', - )[1]; + const accessToken = req.headers['authorization'].replace('Bearer ', ''); + const refreshToken = req.headers['cookie'].split('refreshToken=')[1]; - // accessToken 토큰 - const jwtAccessKey = jwt.verify(accessToken, process.env.JWT_ACCESS_KEY); + const jwtAccessKey = jwt.verify( + accessToken, // + process.env.JWT_ACCESS_KEY, + ); - // refresh 토큰 const jwtRefreshKey = jwt.verify( refreshToken, process.env.JWT_REFRESH_KEY, @@ -87,10 +78,10 @@ export class AuthService { ttl: jwtRefreshKey['exp'] - jwtRefreshKey['iat'], }, ); - // 🚗🚗🚗🚗🚗🚗🚗🚗🚗 res 이용해서 배포 수정해주기 !!! - return '🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊로그아웃에 성공했습니다.'; + + return '로그아웃 성공'; } catch (err) { - throw new UnauthorizedException('로그아웃을 실패했습니다.'); + throw new UnauthorizedException('로그아웃 실패'); } } @@ -111,17 +102,12 @@ export class AuthService { { secret: process.env.JWT_REFRESH_KEY, expiresIn: '2w' }, ); - // 개발 환경 - // res.setHeader('set-Cookie', `refreshToken=${refreshToken}; path=/;`); - - // 배포 환경 ============== 배포 하기 전까지 잠시 주석 ============= - const originList = [ 'http://localhost:3000', - 'http://groomeong.store', // 프론트 도메인 주소?? - 'https://groomeong.store', // 프론트 도메인 주소?? - 'https://www.groomeong.shop/graphql', - // ssl 된 주소 https:// ..... + 'http://127.0.0.1:3000', + 'http://34.64.53.80:3000', + 'https://groomeong.shop', + 'https://groomeong.store', ]; const origin = req.headers.origin; if (originList.includes(origin)) { @@ -146,23 +132,19 @@ export class AuthService { res.setHeader( 'Set-Cookie', - `refreshToken=${refreshToken}; path=/; domain=www.groomeong.shop ; Secure; httpOnly; SameSite=None;`, + `refreshToken=${refreshToken}; path=/; domain=.groomeong.shop; Secure; httpOnly; SameSite=None;`, ); } async loginOAuth({ req, res }: ILoginService): Promise { - // 1. 회원조회 let user = await this.usersService.findOneByEmail({ email: req.user.email, }); + if (!user) { + user = await this.usersService.create({ ...req.user }); + } - // 2. 회원가입이 안되어있다면? 자동 회원가입 - if (!user) user = await this.usersService.create({ ...req.user }); - - // 3. 로그인 브라우저 전송 this.setRefreshToken({ user, res, req }); - - res.redirect('https://groomeong.store/home/'); - // 페이지 수정 꼭 하기! 배포될때!!🚗🚗🚗🚗🚗🚗🚗🚗🚗🚗🚗🚗 프론트 메인 페이지 + res.redirect('https://groomeong.store'); } } diff --git a/src/app.module.ts b/src/app.module.ts index 879afed..b937b6a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -40,6 +40,16 @@ import { HttpExceptionFilter } from './commons/filter/http-exception.filter'; driver: ApolloDriver, autoSchemaFile: true, context: ({ req, res }) => ({ req, res }), + cors: { + origin: [ + 'http://localhost:3000', + 'http://127.0.0.1:3000', + 'http://34.64.53.80:3000', + 'https://groomeong.shop', + 'https://groomeong.store', + ], + credentials: true, + }, }), ConfigModule.forRoot(), MailerModule.forRootAsync({ diff --git a/src/main.ts b/src/main.ts index 7dd069f..ebd72fc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,7 +14,8 @@ async function bootstrap() { 'http://localhost:3000', 'http://127.0.0.1:3000', 'http://34.64.53.80:3000', - 'https://www.groomeong.shop', + 'https://groomeong.shop', + 'https://groomeong.store', ], credentials: true, });