From 9b8765165901fb87d28d452ce9c3fdb1be835de9 Mon Sep 17 00:00:00 2001 From: YOOJS1205 Date: Mon, 12 Feb 2024 18:12:24 +0900 Subject: [PATCH] =?UTF-8?q?body=EC=97=90=20=EB=8B=B4=EA=B2=A8=EC=A7=84=20i?= =?UTF-8?q?d=5Ftoken=20=EC=A0=84=EB=8B=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/middleware.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index 88a0d8e6..538527aa 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -8,10 +8,6 @@ export async function middleware(request: NextRequest) { // NOTE: 메인 페이지 진입 시 토큰이 존재하지 않으면 로그인 페이지로 리다이렉트 if (request.nextUrl.pathname === '/') { - if (request.method === 'POST') { - return NextResponse.redirect(new URL('/', request.url), 303); - } - const cookieAccessToken = request.cookies.get('accessToken'); const cookieRefreshToken = request.cookies.get('refreshToken'); @@ -45,15 +41,20 @@ export async function middleware(request: NextRequest) { // NOTE: 카카오 로그인 > 로그인 api 호출 > 토큰 저장 후 메인페이지 이동 if (request.nextUrl.pathname === '/auth') { + const body = await request.json(); + const provider = request.nextUrl.searchParams.get('type'); const code = request.nextUrl.searchParams.get('code'); + const id_token = body.id_token; const redirect_uri = process.env.NODE_ENV === 'production' ? `${process.env.NEXT_PUBLIC_SITE_DOMAIN}/auth?type=${provider}` : `${process.env.NEXT_PUBLIC_LOCAL_DOMAIN}/auth?type=${provider}`; const res = await fetch( - `${process.env.API_BASE_URL}/api/v1/auth/login?code=${code}&provider=${provider}&redirect_uri=${redirect_uri}`, + `${process.env.API_BASE_URL}/api/v1/auth/login?code=${ + provider === 'kakao' ? code : id_token + }&provider=${provider}&redirect_uri=${redirect_uri}`, ); const responseData = await res.json(); @@ -92,5 +93,5 @@ export async function middleware(request: NextRequest) { } export const config = { - matcher: ['/auth', '/'], + matcher: ['/', '/auth'], };