From 6fc9a1d34643525b981a9cb3ee607d45b2bebb60 Mon Sep 17 00:00:00 2001 From: ghdtjgus76 Date: Sun, 18 Aug 2024 13:45:02 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20utils=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=EC=97=90=20next=20=EC=84=A4=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/utils/package.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/utils/package.json b/packages/utils/package.json index 4ba994ad..5410d84a 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -10,11 +10,14 @@ }, "devDependencies": { "@types/jest": "^29.5.12", + "@wow-class/eslint-config": "workspace:*", "@wow-class/typescript-config": "workspace:*", "jest": "^29.7.0", "jest-fetch-mock": "^3.0.3", - "ts-jest": "^29.2.4", - "@wow-class/eslint-config": "workspace:*", - "typescript": "^5.3.3" + "typescript": "^5.3.3", + "ts-jest": "^29.2.4" + }, + "dependencies": { + "next": "^14.2.5" } } From 78144d7effd87a8d13dbd4f31d6c45d73607c3ff Mon Sep 17 00:00:00 2001 From: ghdtjgus76 Date: Sun, 18 Aug 2024 13:45:20 +0900 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20fetcher=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20client,=20server=20=ED=99=98=EA=B2=BD=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/utils/src/fetcher/index.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/fetcher/index.ts b/packages/utils/src/fetcher/index.ts index df222dc9..c3194f67 100644 --- a/packages/utils/src/fetcher/index.ts +++ b/packages/utils/src/fetcher/index.ts @@ -87,9 +87,14 @@ class Fetcher { ): Promise> { options = await this.interceptRequest(options); + const fetchOptions: RequestInit = { + ...options, + credentials: "include", + }; + const fullUrl = this.baseUrl + url; - let response: ApiResponse = await fetch(fullUrl, options); + let response: ApiResponse = await fetch(fullUrl, fetchOptions); await this.handleError(response); @@ -157,6 +162,8 @@ class Fetcher { } } +const isClient = typeof window !== "undefined"; + const fetcher = new Fetcher({ baseUrl: process.env.NODE_ENV === "production" @@ -165,4 +172,22 @@ const fetcher = new Fetcher({ defaultHeaders: { "Content-Type": "application/json" }, }); +if (!isClient) { + fetcher.addRequestInterceptor(async (options) => { + const { cookies } = await import("next/headers"); + + const cookieStore = cookies(); + const accessToken = cookieStore.get("accessToken")?.value; + + if (accessToken) { + options.headers = { + ...options.headers, + Authorization: `Bearer ${accessToken}`, + }; + } + + return options; + }); +} + export default fetcher; From e7536dda0c7cf00daaadb6bca566d7e27bcb3a38 Mon Sep 17 00:00:00 2001 From: ghdtjgus76 Date: Sun, 18 Aug 2024 13:45:41 +0900 Subject: [PATCH 3/6] =?UTF-8?q?chore:=20root=20=EC=9D=98=EC=A1=B4=EC=84=B1?= =?UTF-8?q?=20=EC=B6=A9=EB=8F=8C=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +-- pnpm-lock.yaml | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9eb5d569..8caa0e99 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "clsx": "^2.1.1", "wowds-icons": "^0.1.3", "wowds-tokens": "^0.1.1", - "wowds-ui": "^0.1.8", - "wowds-icons": "^0.1.2" + "wowds-ui": "^0.1.8" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8a312618..d7995dac 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -261,6 +261,10 @@ importers: version: 5.4.5 packages/utils: + dependencies: + next: + specifier: ^14.2.5 + version: 14.2.5(@babel/core@7.25.2)(react-dom@18.3.1)(react@18.3.1) devDependencies: '@types/jest': specifier: ^29.5.12 From f1b88897d525fc3603ec79cd49ffc043431e1091 Mon Sep 17 00:00:00 2001 From: ghdtjgus76 Date: Sun, 18 Aug 2024 13:45:54 +0900 Subject: [PATCH 4/6] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=97=A4=EB=8D=94=20=EC=A3=BC=EC=9E=85=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/client/apis/dashboardApi.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/apps/client/apis/dashboardApi.ts b/apps/client/apis/dashboardApi.ts index 445b1f2c..6650ad95 100644 --- a/apps/client/apis/dashboardApi.ts +++ b/apps/client/apis/dashboardApi.ts @@ -1,22 +1,14 @@ import { fetcher } from "@wow-class/utils"; import { apiPath } from "constants/apiPath"; import { tags } from "constants/tags"; -import { cookies } from "next/headers"; import type { DashboardApiResponseDto } from "types/dtos/auth"; export const dashboardApi = { getDashboardInfo: async () => { - const cookieStore = cookies(); - const accessToken = cookieStore.get("accessToken")?.value; - - // NOTE: middleware에서 호출하기 위해서 별도로 헤더 주입 const response = await fetcher.get( apiPath.dashboard, { next: { tags: [tags.dashboard] }, - headers: { - Authorization: `Bearer ${accessToken}`, - }, } ); From 6f1c2f3daa3bed48007f99f3f5cb5a1158b0be48 Mon Sep 17 00:00:00 2001 From: ghdtjgus76 Date: Sun, 18 Aug 2024 13:47:56 +0900 Subject: [PATCH 5/6] =?UTF-8?q?chore:=20admin=20=ED=97=A4=EB=8D=94=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EB=A1=9C=EC=A7=81=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/apis/auth/dashboardApi.ts | 9 +-------- apps/admin/middleware.ts | 5 +---- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/apps/admin/apis/auth/dashboardApi.ts b/apps/admin/apis/auth/dashboardApi.ts index f3277ebb..c3a12369 100644 --- a/apps/admin/apis/auth/dashboardApi.ts +++ b/apps/admin/apis/auth/dashboardApi.ts @@ -1,21 +1,14 @@ import { fetcher } from "@wow-class/utils"; import { apiPath } from "constants/apiPath"; import { tags } from "constants/tags"; -import { cookies } from "next/headers"; -import type { DashboardApiResponseDto } from "types/dto/auth"; +import type { DashboardApiResponseDto } from "types/dtos/auth"; export const dashboardApi = { getDashboardInfo: async () => { - const cookieStore = cookies(); - const accessToken = cookieStore.get("accessToken")?.value; - const response = await fetcher.get( apiPath.dashboard, { next: { tags: [tags.dashboard] }, - headers: { - Authorization: `Bearer ${accessToken}`, - }, } ); diff --git a/apps/admin/middleware.ts b/apps/admin/middleware.ts index 7ada0433..4e1e165a 100644 --- a/apps/admin/middleware.ts +++ b/apps/admin/middleware.ts @@ -25,11 +25,8 @@ const middleware = async (req: NextRequest) => { return NextResponse.redirect(new URL("/auth", url)); } - const response = NextResponse.next(); - response.headers.set("Authorization", `Bearer ${accessToken}`); - - return response; + return NextResponse.next(); }; export default middleware; From 56f13bfcc949ff041ec3e532088727d11d290937 Mon Sep 17 00:00:00 2001 From: ghdtjgus76 Date: Sun, 18 Aug 2024 13:59:51 +0900 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20=EB=B9=8C=EB=93=9C=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=ED=95=98=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c62b904f..b072307f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: run_install: false - name: Install dependencies - run: pnpm install + run: pnpm install --no-frozen-lockfile - name: Run build run: pnpm run build