From 0134cc0db70e4278381d17f7a07ff3fbeced93d5 Mon Sep 17 00:00:00 2001 From: ghdtjgus76 Date: Tue, 13 Aug 2024 22:28:16 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=AF=B8=EB=93=A4=EC=9B=A8=EC=96=B4=20?= =?UTF-8?q?=EB=B0=8F=20fetch=20=ED=97=A4=EB=8D=94=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/client/app/(beforeLogin)/auth/page.tsx | 27 ++++++++++++++++++- .../social-login/redirect/page.tsx | 8 ++++++ apps/client/middleware.ts | 26 +++++++++++------- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/apps/client/app/(beforeLogin)/auth/page.tsx b/apps/client/app/(beforeLogin)/auth/page.tsx index d6553b8a..9c4a372d 100644 --- a/apps/client/app/(beforeLogin)/auth/page.tsx +++ b/apps/client/app/(beforeLogin)/auth/page.tsx @@ -1,8 +1,33 @@ import { css } from "@styled-system/css"; +import { fetcher } from "@wow-class/utils"; import LoginButton from "components/LoginButton"; +import { apiPath } from "constants/apiPath"; +import { tags } from "constants/tags"; +import { cookies } from "next/headers"; import Image from "next/image"; +import type { DashboardApiResponseDto } from "types/dtos/auth"; + +const AuthPage = async () => { + const cookieStore = cookies(); + const accessToken = cookieStore.get("accessToken")?.value; + + const response = await fetcher.get( + apiPath.dashboard, + { + next: { tags: [tags.dashboard] }, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${accessToken}`, + }, + } + ); + + const memberRole = response.data?.member.role; + const currentRecruitmentOpen = + response.data?.currentRecruitmentRound.period.open; + + console.log(memberRole, currentRecruitmentOpen); -const AuthPage = () => { return (
diff --git a/apps/client/app/(beforeLogin)/social-login/redirect/page.tsx b/apps/client/app/(beforeLogin)/social-login/redirect/page.tsx index 38f4ba39..c60a0353 100644 --- a/apps/client/app/(beforeLogin)/social-login/redirect/page.tsx +++ b/apps/client/app/(beforeLogin)/social-login/redirect/page.tsx @@ -2,14 +2,22 @@ import { fetcher } from "@wow-class/utils"; import { apiPath } from "constants/apiPath"; import { routePath } from "constants/routePath"; import { tags } from "constants/tags"; +import { cookies } from "next/headers"; import { redirect } from "next/navigation"; import type { DashboardApiResponseDto } from "types/dtos/auth"; const AuthServerRedirectPage = async () => { + const cookieStore = cookies(); + const accessToken = cookieStore.get("accessToken")?.value; + const response = await fetcher.get( apiPath.dashboard, { next: { tags: [tags.dashboard] }, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${accessToken}`, + }, } ); diff --git a/apps/client/middleware.ts b/apps/client/middleware.ts index 7785572a..41071560 100644 --- a/apps/client/middleware.ts +++ b/apps/client/middleware.ts @@ -2,19 +2,25 @@ import { cookies } from "next/headers"; import type { NextRequest } from "next/server"; import { NextResponse } from "next/server"; -export const config = { - matcher: ["/my-page/:path*", "/my-study/:path*", "/study-apply/:path*"], -}; +export function middleware(request: NextRequest) { + const requestHeaders = new Headers(request.headers); -const middleware = (req: NextRequest) => { const cookieStore = cookies(); - const accessToken = cookieStore.get("accessToken"); + const accessToken = cookieStore.get("accessToken")?.value; - if (!accessToken) { - return NextResponse.redirect(new URL("/auth", req.url)); + if (accessToken) { + requestHeaders.set("Authorization", `Bearer ${accessToken}`); } - return NextResponse.next(); -}; + requestHeaders.set("Content-Type", "application/json"); -export default middleware; + return NextResponse.next({ + request: { + headers: requestHeaders, + }, + }); +} + +export const config = { + matcher: ["/my-page/:path*", "/my-study/:path*", "/study-apply/:path*"], +};