Skip to content

Commit

Permalink
Merge pull request #177 from Moaguide-develop/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
eun-hak authored Dec 2, 2024
2 parents 78dd85a + 541eae0 commit 1b83e29
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 56 deletions.
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import GnbWrapper from '@/components/common/GnbWrapper';

import './plugin';
import NaverAnalytics from '@/lib/NaverAnalytics';
import AuthWrapper from '@/components/common/AuthWrapper';

declare global {
interface Window {
Expand Down Expand Up @@ -96,6 +97,7 @@ export default function RootLayout({
strategy="beforeInteractive"
src={`//dapi.kakao.com/v2/maps/sdk.js?appkey=${process.env.NEXT_PUBLIC_MAP_KEY}&autoload=false`}
/>
<AuthWrapper />
<GnbWrapper />
{children}
<MobileFooter />
Expand Down
29 changes: 29 additions & 0 deletions src/components/common/AuthWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use client';

import { useEffect } from 'react';
import { usePathname, useRouter } from 'next/navigation';
import { getCookie } from '@/utils/cookie';

const GnbWrapper = () => {
const pathname = usePathname();
const router = useRouter();
const token = getCookie('access_token');
useEffect(() => {
if (
!token &&
pathname !== '/sign' &&
pathname !== '/signin' &&
pathname !== '/signup' &&
pathname !== '/find' &&
// pathname !== '/search' &&
pathname !== '/'
) {
alert('로그인이 필요한 서비스입니다.');
router.replace('/sign');
}
}, [router, pathname, token]);

return null;
};

export default GnbWrapper;
1 change: 0 additions & 1 deletion src/components/common/GnbWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Gnb from '@/components/common/Gnb';
const GnbWrapper = () => {
const pathname = usePathname();
const [isGnbHidden, setIsGnbHidden] = useState(false);

useEffect(() => {
const checkIfGnbShouldBeHidden = () => {
const pathsToHideGnb = ['/signup', '/sign', '/find', '/detail', '/login', '/quiz'];
Expand Down
17 changes: 3 additions & 14 deletions src/components/common/MobileFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use client';
import { useAuthStore } from '@/store/userAuth.store';
import { usePathname, useRouter } from 'next/navigation';
import React from 'react';

const MobileFooter = () => {
const router = useRouter();
const pathname = usePathname(); // 추가된 부분
const { isLoggedIn } = useAuthStore();
if (pathname.startsWith('/quiz/')) return null;
return (
<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 ">
Expand All @@ -23,10 +21,7 @@ const MobileFooter = () => {
</div>
<div
onClick={() => {
isLoggedIn
? router.push('/newissue')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/newissue');
router.push('/newissue');
}}
className="flex-1 flex flex-col gap-1 items-center">
<div>
Expand All @@ -39,10 +34,7 @@ const MobileFooter = () => {
</div>
<div
onClick={() => {
isLoggedIn
? router.push('/product')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/product');
router.push('/product');
}}
className="flex-1 flex flex-col gap-1 items-center">
<div>
Expand All @@ -55,10 +47,7 @@ const MobileFooter = () => {
</div>
<div
onClick={() => {
isLoggedIn
? router.push('/practicepage')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/practicepage');
router.push('/practicepage');
}}
className="flex-1 flex flex-col gap-1 items-center">
<div>
Expand Down
17 changes: 3 additions & 14 deletions src/components/common/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import React from 'react';
import { useRouter, usePathname } from 'next/navigation';
import { useAuthStore } from '@/store/userAuth.store';

const Navbar = () => {
const router = useRouter();
const pathname = usePathname();
const { isLoggedIn } = useAuthStore();
return (
<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]">
<div className="max-w-[1000px] mx-auto flex items-center">
Expand All @@ -22,10 +20,7 @@ const Navbar = () => {
</div>
<div
onClick={() => {
isLoggedIn
? router.push('/newissue')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/newissue');
router.push('/newissue');
}}
className={` desk:whitespace-nowrap px-4 py-3 flex-1 flex justify-center items-center cursor-pointer text-body5 desk2:text-heading4
${pathname === '/newissue' ? 'text-black border-b-[2px] border-black' : 'text-gray300'}
Expand All @@ -34,10 +29,7 @@ const Navbar = () => {
</div>
<div
onClick={() => {
isLoggedIn
? router.push('/product')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/product');
router.push('/product');
}}
className={` desk:whitespace-nowrap px-4 py-3 flex-1 flex justify-center items-center cursor-pointer text-body5 desk2:text-heading4
${pathname === '/product' ? 'text-black border-b-[2px] border-black' : 'text-gray300'}
Expand All @@ -46,10 +38,7 @@ const Navbar = () => {
</div>
<div
onClick={() => {
isLoggedIn
? router.push('/practicepage')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/practicepage');
router.push('/practicepage');
}}
className={` desk:whitespace-nowrap px-4 py-3 flex-1 flex justify-center items-center cursor-pointer text-body5 desk2:text-heading4
${pathname === '/practicepage' ? 'text-black border-b-[2px] border-black' : 'text-gray300'}
Expand Down
33 changes: 6 additions & 27 deletions src/components/home/SubMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { useAuthStore } from '@/store/userAuth.store';
import Image from 'next/image';
import { useRouter } from 'next/navigation';
import React from 'react';

const SubMenu = () => {
const router = useRouter();
const { isLoggedIn } = useAuthStore();
return (
<div>
{/* 데스크톱 */}
<div className="items-center gap-3 hidden sm:flex">
<div
onClick={() => {
isLoggedIn
? router.push('/newissue')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/newissue');
router.push('/newissue');
}}
className="cursor-pointer flex-1 flex items-center justify-between px-[16px] md:px-[28px] py-[22px] rounded-[12px] bg-bg">
<div className=" text-body5 text-gray700 desk2:text-title2">최신 이슈</div>
Expand All @@ -25,10 +19,7 @@ const SubMenu = () => {
</div>
<div
onClick={() => {
isLoggedIn
? router.push('/product')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/product');
router.push('/product');
}}
className="cursor-pointer flex-1 flex items-center justify-between px-[16px] md:px-[28px] py-[22px] rounded-[12px] bg-bg">
<div className=" text-caption1 text-gray700 desk2:text-title2">
Expand All @@ -40,10 +31,7 @@ const SubMenu = () => {
</div>
<div
onClick={() => {
isLoggedIn
? router.push('/practicepage')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/practicepage');
router.push('/practicepage');
}}
className="cursor-pointer flex-1 flex items-center justify-between px-[16px] md:px-[28px] py-[22px] rounded-[12px] bg-bg">
<div className=" text-body5 text-gray700 desk2:text-title2">학습하기</div>
Expand Down Expand Up @@ -79,10 +67,7 @@ const SubMenu = () => {
<div className="sm:hidden flex justify-center gap-[12px]">
<div
onClick={() => {
isLoggedIn
? router.push('/newissue')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/newissue');
router.push('/newissue');
}}
className="max-w-[110px] w-full py-4 flex flex-col justify-center items-center gap-3 rounded-[12px] border border-gray100">
<div>
Expand All @@ -92,10 +77,7 @@ const SubMenu = () => {
</div>
<div
onClick={() => {
isLoggedIn
? router.push('/product')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/product');
router.push('/product');
}}
className="max-w-[110px] w-full py-4 flex flex-col justify-center items-center gap-3 rounded-[12px] border border-gray100">
<div>
Expand All @@ -105,10 +87,7 @@ const SubMenu = () => {
</div>
<div
onClick={() => {
isLoggedIn
? router.push('/practicepage')
: (alert('로그인이 필요한 서비스입니다 '), router.push('/sign'));
// router.push('/practicepage');
router.push('/practicepage');
}}
className="max-w-[110px] w-full py-4 flex flex-col justify-center items-center gap-3 rounded-[12px] border border-gray100">
<div>
Expand Down
37 changes: 37 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { cookies } from 'next/headers';

export function middleware(request: NextRequest) {
// const getCookie = (key: string) => {
// return cookies().get(key)?.value;
// };

// const token = getCookie('access_token');
// const pathname = request.nextUrl.pathname;

// const dynamicRouteRegex = /^\/product\/detail\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_.-]+$/;
// if (!token && dynamicRouteRegex.test(pathname)) {
// console.log('Dynamic route detected:', pathname);
// return NextResponse.redirect(new URL('/sign', request.url));
// }
// if (
// pathname.startsWith('/api') ||
// pathname.includes('.') ||
// pathname.startsWith('/_next/static/') ||
// pathname.startsWith('/favicon') ||
// pathname === '/manifest.json' ||
// pathname.startsWith('/icons/')
// ) {
// return NextResponse.next();
// }
// console.log('middleware full URL:', request.nextUrl.href);
// if (
// !token &&
// !['/sign', '/signin', '/signup', '/find', '/search', '/'].includes(pathname)
// ) {
// return NextResponse.redirect(new URL('/sign', request.url));
// }

return NextResponse.next();
}

0 comments on commit 1b83e29

Please sign in to comment.