Skip to content

Commit

Permalink
[#39] Fix: middleware 작업 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
DHyeon98 committed Jun 21, 2024
1 parent 576e476 commit 12bc7d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions utils/constants/middleware-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export class MiddlewareData {
'/calendar/:path*',
'/growth/:path*',
'/story/:path*',
'/mypage/:path*',
];
}

0 comments on commit 12bc7d2

Please sign in to comment.