Skip to content

Commit ee60494

Browse files
committed
fix: private route 설정
1 parent ff44a1e commit ee60494

File tree

4 files changed

+61
-36
lines changed

4 files changed

+61
-36
lines changed

src/components/common/GnbWrapper.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
'use client';
22

33
import { useEffect, useState } from 'react';
4-
import { usePathname, useRouter } from 'next/navigation';
4+
import { usePathname } from 'next/navigation';
55
import Gnb from '@/components/common/Gnb';
6-
import { getCookie } from '@/utils/cookie';
76

87
const GnbWrapper = () => {
9-
const router = useRouter();
10-
const token = getCookie('access_token');
118
const pathname = usePathname();
129
const [isGnbHidden, setIsGnbHidden] = useState(false);
1310

@@ -20,24 +17,6 @@ const GnbWrapper = () => {
2017

2118
checkIfGnbShouldBeHidden();
2219
}, [pathname]);
23-
24-
useEffect(() => {
25-
console.log('client middleware', pathname);
26-
27-
if (
28-
!token &&
29-
pathname !== '/sign' &&
30-
pathname !== '/signin' &&
31-
pathname !== '/signup' &&
32-
pathname !== '/find' &&
33-
pathname !== '/search' &&
34-
pathname !== '/'
35-
) {
36-
alert('로그인이 필요한 서비스입니다.');
37-
router.push('/sign');
38-
}
39-
}, [router, pathname, token]);
40-
4120
return !isGnbHidden ? <Gnb /> : null;
4221
};
4322

src/components/common/MobileFooter.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
'use client';
2+
import { useAuthStore } from '@/store/userAuth.store';
23
import { usePathname, useRouter } from 'next/navigation';
34
import React from 'react';
45

56
const MobileFooter = () => {
67
const router = useRouter();
78
const pathname = usePathname(); // 추가된 부분
9+
const { isLoggedIn } = useAuthStore();
810
if (pathname.startsWith('/quiz/')) return null;
911
return (
1012
<div className="sm:hidden z-[999999] sticky bottom-0 pt-[14px] pb-[18px] px-[6px] flex items-center border-t border-gray100 bg-white w-full ">
@@ -20,7 +22,12 @@ const MobileFooter = () => {
2022
<div className="text-caption1 text-gray300"></div>
2123
</div>
2224
<div
23-
onClick={() => router.push('/newissue')}
25+
onClick={() => {
26+
isLoggedIn
27+
? router.push('/newissue')
28+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
29+
// router.push('/newissue');
30+
}}
2431
className="flex-1 flex flex-col gap-1 items-center">
2532
<div>
2633
<img
@@ -31,7 +38,12 @@ const MobileFooter = () => {
3138
<div className="text-caption1 text-gray300">최신 이슈</div>
3239
</div>
3340
<div
34-
onClick={() => router.push('/product')}
41+
onClick={() => {
42+
isLoggedIn
43+
? router.push('/product')
44+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
45+
// router.push('/product');
46+
}}
3547
className="flex-1 flex flex-col gap-1 items-center">
3648
<div>
3749
<img
@@ -42,7 +54,12 @@ const MobileFooter = () => {
4254
<div className="text-caption1 text-gray300">조각투자 상품</div>
4355
</div>
4456
<div
45-
onClick={() => router.push('/practicepage')}
57+
onClick={() => {
58+
isLoggedIn
59+
? router.push('/practicepage')
60+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
61+
// router.push('/practicepage');
62+
}}
4663
className="flex-1 flex flex-col gap-1 items-center">
4764
<div>
4865
<img

src/components/common/Navbar.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import React from 'react';
44
import { useRouter, usePathname } from 'next/navigation';
5+
import { useAuthStore } from '@/store/userAuth.store';
56

67
const Navbar = () => {
78
const router = useRouter();
89
const pathname = usePathname();
9-
10+
const { isLoggedIn } = useAuthStore();
1011
return (
1112
<div className="hidden bg-white shadow-custom-light border-b desk:h-[60px] md:h-full border-gray100 sm:block desk:w-full lg:w-[100%] sticky top-[58px] z-[99998]">
1213
<div className="max-w-[1000px] mx-auto flex items-center">
@@ -21,7 +22,10 @@ const Navbar = () => {
2122
</div>
2223
<div
2324
onClick={() => {
24-
router.push('/newissue');
25+
isLoggedIn
26+
? router.push('/newissue')
27+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
28+
// router.push('/newissue');
2529
}}
2630
className={` desk:whitespace-nowrap px-4 py-3 flex-1 flex justify-center items-center cursor-pointer text-body5 desk2:text-heading4
2731
${pathname === '/newissue' ? 'text-black border-b-[2px] border-black' : 'text-gray300'}
@@ -30,7 +34,10 @@ const Navbar = () => {
3034
</div>
3135
<div
3236
onClick={() => {
33-
router.push('/product');
37+
isLoggedIn
38+
? router.push('/product')
39+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
40+
// router.push('/product');
3441
}}
3542
className={` desk:whitespace-nowrap px-4 py-3 flex-1 flex justify-center items-center cursor-pointer text-body5 desk2:text-heading4
3643
${pathname === '/product' ? 'text-black border-b-[2px] border-black' : 'text-gray300'}
@@ -39,7 +46,10 @@ const Navbar = () => {
3946
</div>
4047
<div
4148
onClick={() => {
42-
router.push('/practicepage');
49+
isLoggedIn
50+
? router.push('/practicepage')
51+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
52+
// router.push('/practicepage');
4353
}}
4454
className={` desk:whitespace-nowrap px-4 py-3 flex-1 flex justify-center items-center cursor-pointer text-body5 desk2:text-heading4
4555
${pathname === '/practicepage' ? 'text-black border-b-[2px] border-black' : 'text-gray300'}

src/components/home/SubMenu.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
import { useAuthStore } from '@/store/userAuth.store';
12
import Image from 'next/image';
23
import { useRouter } from 'next/navigation';
34
import React from 'react';
45

56
const SubMenu = () => {
67
const router = useRouter();
7-
8+
const { isLoggedIn } = useAuthStore();
89
return (
910
<div>
1011
{/* 데스크톱 */}
1112
<div className="items-center gap-3 hidden sm:flex">
1213
<div
1314
onClick={() => {
14-
router.push('/newissue');
15+
isLoggedIn
16+
? router.push('/newissue')
17+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
18+
// router.push('/newissue');
1519
}}
1620
className="cursor-pointer flex-1 flex items-center justify-between px-[16px] md:px-[28px] py-[22px] rounded-[12px] bg-bg">
1721
<div className=" text-body5 text-gray700 desk2:text-title2">최신 이슈</div>
@@ -21,7 +25,10 @@ const SubMenu = () => {
2125
</div>
2226
<div
2327
onClick={() => {
24-
router.push('/product');
28+
isLoggedIn
29+
? router.push('/product')
30+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
31+
// router.push('/product');
2532
}}
2633
className="cursor-pointer flex-1 flex items-center justify-between px-[16px] md:px-[28px] py-[22px] rounded-[12px] bg-bg">
2734
<div className=" text-caption1 text-gray700 desk2:text-title2">
@@ -33,7 +40,10 @@ const SubMenu = () => {
3340
</div>
3441
<div
3542
onClick={() => {
36-
router.push('/practicepage');
43+
isLoggedIn
44+
? router.push('/practicepage')
45+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
46+
// router.push('/practicepage');
3747
}}
3848
className="cursor-pointer flex-1 flex items-center justify-between px-[16px] md:px-[28px] py-[22px] rounded-[12px] bg-bg">
3949
<div className=" text-body5 text-gray700 desk2:text-title2">학습하기</div>
@@ -69,7 +79,10 @@ const SubMenu = () => {
6979
<div className="sm:hidden flex justify-center gap-[12px]">
7080
<div
7181
onClick={() => {
72-
router.push('/newissue');
82+
isLoggedIn
83+
? router.push('/newissue')
84+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
85+
// router.push('/newissue');
7386
}}
7487
className="max-w-[110px] w-full py-4 flex flex-col justify-center items-center gap-3 rounded-[12px] border border-gray100">
7588
<div>
@@ -79,7 +92,10 @@ const SubMenu = () => {
7992
</div>
8093
<div
8194
onClick={() => {
82-
router.push('/product');
95+
isLoggedIn
96+
? router.push('/product')
97+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
98+
// router.push('/product');
8399
}}
84100
className="max-w-[110px] w-full py-4 flex flex-col justify-center items-center gap-3 rounded-[12px] border border-gray100">
85101
<div>
@@ -89,7 +105,10 @@ const SubMenu = () => {
89105
</div>
90106
<div
91107
onClick={() => {
92-
router.push('/practicepage');
108+
isLoggedIn
109+
? router.push('/practicepage')
110+
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
111+
// router.push('/practicepage');
93112
}}
94113
className="max-w-[110px] w-full py-4 flex flex-col justify-center items-center gap-3 rounded-[12px] border border-gray100">
95114
<div>

0 commit comments

Comments
 (0)