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 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; 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}`, - }, } ); 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/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" } } 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; 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