From afe3fdf51fae1bc5f4b5eca740895c0b585c61ce Mon Sep 17 00:00:00 2001 From: YOOJS1205 Date: Tue, 30 Jan 2024 04:23:37 +0900 Subject: [PATCH 1/4] =?UTF-8?q?middleware=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/middleware.ts | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index 13cca97a..664fed9b 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -7,10 +7,10 @@ export function middleware(request: NextRequest) { const isFirstLogin = request.nextUrl.searchParams.get('isFirst') as string; const isFromApp = request.nextUrl.searchParams.get('fromApp'); + const url = request.nextUrl.clone(); + // NOTE: splash 화면으로 넘어왔을 때 쿠키 내의 토큰 여부에 따른 리다이렉트 로직 if (isFromApp === 'true') { - const url = request.nextUrl.clone(); - if (accessToken && refreshToken) { url.pathname = '/'; } else { @@ -18,24 +18,19 @@ export function middleware(request: NextRequest) { } url.search = ''; - - const response = NextResponse.redirect(url); - - return response; - } - - // 웹 - const url = request.nextUrl.clone(); - - if (isFirstLogin === 'true') { - url.pathname = '/terms'; } else { - url.pathname = '/'; - } + // 웹 + if (isFirstLogin === 'true') { + url.pathname = '/terms'; + } else { + url.pathname = '/'; + } - url.search = ''; + url.search = ''; + } const response = NextResponse.redirect(url); + if (accessToken && refreshToken) { response.cookies.set('accessToken', accessToken, { path: '/' }); response.cookies.set('refreshToken', refreshToken, { path: '/' }); From 5effb3858d86108447a40c24926139a3ab0df5d6 Mon Sep 17 00:00:00 2001 From: YOOJS1205 Date: Tue, 30 Jan 2024 18:58:24 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=ED=97=A4=EB=8D=94=EC=97=90=20z-index=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/api-config.ts | 19 ++++++++++--------- src/app/review/page.tsx | 2 +- src/middleware.ts | 7 +++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/api/api-config.ts b/src/api/api-config.ts index 596cf7fd..7e500b0c 100644 --- a/src/api/api-config.ts +++ b/src/api/api-config.ts @@ -92,16 +92,17 @@ axiosInstance.interceptors.response.use( config.sent = true; const refreshToken = Cookies.get('refreshToken'); + // NOTE: 401 에러인데, refreshToken이 존재하지 않으면 로그아웃 // NOTE: 토큰 재발급 요청 - if ( - config.url !== TOKEN_REFRESH_URL && - response.data.code === 401 && - refreshToken - ) { - const { data } = await getTokenRefresh(); - Cookies.set('accessToken', data.accessToken); - config.headers['Authorization'] = data.accessToken; - return axios(config); + if (config.url !== TOKEN_REFRESH_URL && response.data.code === 401) { + if (refreshToken) { + const { data } = await getTokenRefresh(); + Cookies.set('accessToken', data.accessToken); + config.headers['Authorization'] = data.accessToken; + return axios(config); + } else { + logout(); + } } // NOTE: 토큰 재발급 요청이 유효하지 않으면, 쿠키의 토큰을 삭제하고 로그아웃 처리. 로그인 페이지로 이동 diff --git a/src/app/review/page.tsx b/src/app/review/page.tsx index ded74211..574e17a1 100644 --- a/src/app/review/page.tsx +++ b/src/app/review/page.tsx @@ -106,7 +106,7 @@ export default function Page() { return (
-
+

로그 작성

diff --git a/src/middleware.ts b/src/middleware.ts index 664fed9b..6ed2b5ce 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -16,19 +16,18 @@ export function middleware(request: NextRequest) { } else { url.pathname = '/login'; } - - url.search = ''; } else { + console.log(isFirstLogin); // 웹 if (isFirstLogin === 'true') { url.pathname = '/terms'; } else { url.pathname = '/'; } - - url.search = ''; } + url.search = ''; + const response = NextResponse.redirect(url); if (accessToken && refreshToken) { From 49c46523c1f34f6acfe79172907c8cfb14d22b0c Mon Sep 17 00:00:00 2001 From: YOOJS1205 Date: Tue, 30 Jan 2024 19:05:56 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EB=92=A4=EB=A1=9C=EA=B0=80=EA=B8=B0=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=EC=9D=80=20=EB=A9=94=EC=9D=B8=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=EB=A1=9C=20=EC=9D=B4=EB=8F=99=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/mypage/layout.tsx | 9 ++++++++- src/components/common/Header/index.tsx | 13 +++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/app/mypage/layout.tsx b/src/app/mypage/layout.tsx index 28166691..c3994470 100644 --- a/src/app/mypage/layout.tsx +++ b/src/app/mypage/layout.tsx @@ -11,11 +11,18 @@ interface LayoutProps { export default function Layout({ children }: LayoutProps) { const router = useRouter(); + const handleClickBackButton = () => { + router.push('/'); + }; + const handleClickSettingButton = () => router.push('/settings'); return (
-
+
{children} diff --git a/src/components/common/Header/index.tsx b/src/components/common/Header/index.tsx index affc7742..ff68482b 100644 --- a/src/components/common/Header/index.tsx +++ b/src/components/common/Header/index.tsx @@ -6,15 +6,24 @@ import { HTMLAttributes } from 'react'; import cn from '@utils/cn'; import LeftArrow from 'public/assets/icon24/left_arrow_24.svg'; +interface HeaderProps extends HTMLAttributes { + onClick?: () => void; +} + export default function Header({ className, children, + onClick, ...restProps -}: HTMLAttributes) { +}: HeaderProps) { const { back } = useRouter(); const handleClickBackButton = () => { - back(); + if (onClick) { + onClick(); + } else { + back(); + } }; return ( From 7a8b0c282653b4f8538b4ccc10ad123fbc703691 Mon Sep 17 00:00:00 2001 From: YOOJS1205 Date: Tue, 30 Jan 2024 21:05:35 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=EC=B2=AB=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=97=AC=EB=B6=80=20=EB=B6=84=EA=B8=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/middleware.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index 6ed2b5ce..73dc6894 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -11,15 +11,15 @@ export function middleware(request: NextRequest) { // NOTE: splash 화면으로 넘어왔을 때 쿠키 내의 토큰 여부에 따른 리다이렉트 로직 if (isFromApp === 'true') { + console.log(accessToken, refreshToken); if (accessToken && refreshToken) { url.pathname = '/'; } else { url.pathname = '/login'; } } else { - console.log(isFirstLogin); // 웹 - if (isFirstLogin === 'true') { + if (isFirstLogin === 'True') { url.pathname = '/terms'; } else { url.pathname = '/';