From 576e4763c54a24c3ab3fa3509d0f5ef4f7928997 Mon Sep 17 00:00:00 2001 From: LimDong Date: Fri, 21 Jun 2024 23:55:51 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[#39]=20Fix:=20nav=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/my/groups/index.ts | 8 ++++---- components/common/nav/nav-list/nav-list-item.tsx | 3 ++- .../delete-modal/delete-modal.tsx | 2 +- .../{family => family-management}/index.module.scss | 0 pages/mypage/{family => family-management}/index.tsx | 0 utils/is-nav.ts | 12 ++++++++++-- 6 files changed, 17 insertions(+), 8 deletions(-) rename pages/mypage/{family => family-management}/index.module.scss (100%) rename pages/mypage/{family => family-management}/index.tsx (100%) diff --git a/api/my/groups/index.ts b/api/my/groups/index.ts index 7ba0ed6a..a5bc7c1b 100644 --- a/api/my/groups/index.ts +++ b/api/my/groups/index.ts @@ -31,18 +31,18 @@ export default class MyFamilyApi { } async myFamilyDelete() { - return axiosInstance.delete(`/my/groups`); + return await axiosInstance.delete(`/my/groups`); } async myFamilyModify(formData: NameModifyType) { - return axiosInstance.put(`/my/groups`, formData); + return await axiosInstance.put(`/my/groups`, formData); } async myFamilyAddMember(formData: FieldValues) { - return axiosInstance.post(`/my/groups/members`, formData); + return await axiosInstance.post(`/my/groups/members`, formData); } async myFamilyDeleteMember(targetId: number) { - return axiosInstance.post(`/my/groups/members/${targetId}`); + return await axiosInstance.post(`/my/groups/members/${targetId}`); } } diff --git a/components/common/nav/nav-list/nav-list-item.tsx b/components/common/nav/nav-list/nav-list-item.tsx index 6548c12a..c588f802 100644 --- a/components/common/nav/nav-list/nav-list-item.tsx +++ b/components/common/nav/nav-list/nav-list-item.tsx @@ -5,8 +5,9 @@ import { NavListProps } from '../types/nav'; export default function NavListItem({ href, text, RenderSvgComponent }: NavListProps) { const { pathname } = useRouter(); + console.log(pathname, href); return ( -
  • +
  • diff --git a/components/mypage/family/family-util-buttons/family-delete-button/delete-modal/delete-modal.tsx b/components/mypage/family/family-util-buttons/family-delete-button/delete-modal/delete-modal.tsx index 0ba9bc16..2b29b89a 100644 --- a/components/mypage/family/family-util-buttons/family-delete-button/delete-modal/delete-modal.tsx +++ b/components/mypage/family/family-util-buttons/family-delete-button/delete-modal/delete-modal.tsx @@ -21,7 +21,7 @@ export default function DeleteModal({ Modal, handleModal }: DeleteModalType) { await myFamilyApi.myFamilyDelete(); deleteCookie('accessToken'); deleteCookie('refreshToken'); - router.push('/login'); + router.push('/'); } catch { console.log('에러'); } diff --git a/pages/mypage/family/index.module.scss b/pages/mypage/family-management/index.module.scss similarity index 100% rename from pages/mypage/family/index.module.scss rename to pages/mypage/family-management/index.module.scss diff --git a/pages/mypage/family/index.tsx b/pages/mypage/family-management/index.tsx similarity index 100% rename from pages/mypage/family/index.tsx rename to pages/mypage/family-management/index.tsx diff --git a/utils/is-nav.ts b/utils/is-nav.ts index 48d17d2a..ae23c48b 100644 --- a/utils/is-nav.ts +++ b/utils/is-nav.ts @@ -1,7 +1,15 @@ import { NextRouter } from 'next/router'; export const isNav = (router: NextRouter) => { - const navPaths = ['/calendar', '/family', '/diaries', '/growth', '/story']; - console.log(navPaths.some((path) => router.pathname === path)); + const navPaths = [ + '/calendar', + '/family', + '/diaries', + '/growth', + '/story', + '/mypage', + '/mypage/pet', + '/mypage/family-management', + ]; return navPaths.some((path) => router.pathname === path); }; From 12bc7d2d2966153945fc3df6381969112550c913 Mon Sep 17 00:00:00 2001 From: LimDong Date: Sat, 22 Jun 2024 00:59:42 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[#39]=20Fix:=20middleware=20=EC=9E=91?= =?UTF-8?q?=EC=97=85=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware.ts | 9 +++++---- utils/constants/middleware-data.ts | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/middleware.ts b/middleware.ts index c7bdebc5..88fd7e25 100644 --- a/middleware.ts +++ b/middleware.ts @@ -8,11 +8,11 @@ export default function middleware(request: NextRequest) { const { cookies, nextUrl } = request; const path = nextUrl.pathname; const hasCookie = cookies.has('accessToken'); - const hasFamily = cookies.has('isFamily'); + const hasFamily = cookies.get('isFamily')?.value === 'true'; const isProtectedPage = PROTECTED_PAGES.some((page) => path.startsWith(page)); const isPublicPage = PUBLIC_PAGES.includes(path); const isNonFamilyPage = NON_FAMILY_PAGES.includes(path); - const isFamilyPage = FAMILY_PAGES.includes(path); + const isFamilyPage = FAMILY_PAGES.some((page) => path.startsWith(page)); // 정적 파일 요청 필터링 if ( @@ -47,12 +47,13 @@ export default function middleware(request: NextRequest) { } // 가족이 있을 때 접근 불가 - if (hasFamily && isNonFamilyPage) { + if (hasCookie && hasFamily && isNonFamilyPage) { return NextResponse.redirect(new URL('/family', request.nextUrl)); } + console.log(isFamilyPage, !hasFamily, hasCookie); // 가족이 없을 때 접근 불가 - if (!hasFamily && isFamilyPage) { + if (hasCookie && !hasFamily && isFamilyPage) { return NextResponse.redirect(new URL('/start-family', request.nextUrl)); } return NextResponse.next(); diff --git a/utils/constants/middleware-data.ts b/utils/constants/middleware-data.ts index 0da84d46..7b305a38 100644 --- a/utils/constants/middleware-data.ts +++ b/utils/constants/middleware-data.ts @@ -15,5 +15,6 @@ export class MiddlewareData { '/calendar/:path*', '/growth/:path*', '/story/:path*', + '/mypage/:path*', ]; } From 8b945aeb1e763be5098be8f665d30392deed4bf7 Mon Sep 17 00:00:00 2001 From: LimDong Date: Sat, 22 Jun 2024 01:05:46 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[#39]=20Fix:=20console=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/common/nav/nav-list/nav-list-item.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/components/common/nav/nav-list/nav-list-item.tsx b/components/common/nav/nav-list/nav-list-item.tsx index c588f802..45b306b2 100644 --- a/components/common/nav/nav-list/nav-list-item.tsx +++ b/components/common/nav/nav-list/nav-list-item.tsx @@ -5,7 +5,6 @@ import { NavListProps } from '../types/nav'; export default function NavListItem({ href, text, RenderSvgComponent }: NavListProps) { const { pathname } = useRouter(); - console.log(pathname, href); return (