Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/api/axiosInstance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';

import { HTTP_STATUS } from '@/constants/common/httpStatus';
import { PATH } from '@/constants/common/path';

export const axiosInstance = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL,
Expand All @@ -26,6 +27,8 @@ axiosInstance.interceptors.response.use(
const { response, config } = error;

if (response?.status === HTTP_STATUS.UNAUTHORIZED) {
localStorage.removeItem('accessToken');
window.location.href = PATH.INTRO;
}

if (response) {
Expand All @@ -36,6 +39,7 @@ axiosInstance.interceptors.response.use(
} else {
console.error('🚨[API NETWORK ERROR], error.message');
}

return Promise.reject(error);
},
);
4 changes: 2 additions & 2 deletions src/components/layout/Header/HomeHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const HomeHeader = ({ hasMenu = false, bgColor }: HomeHeaderProps) => {

const hasToken = useHasToken();

const handleClose = () => {
const handleLogoClick = () => {
if (hasToken) router.push(PATH.INTRO);
router.push(PATH.HOME);
};
Expand All @@ -35,7 +35,7 @@ const HomeHeader = ({ hasMenu = false, bgColor }: HomeHeaderProps) => {
<>
<BaseHeader
leftSlot={
<button onClick={handleClose}>
<button onClick={handleLogoClick}>
<Image
src="/images/logo.svg"
alt="위시풀 로고"
Expand Down
11 changes: 3 additions & 8 deletions src/components/layout/NavMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use client';

import { usePathname, useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';

import { PATH } from '@/constants/common/path';
import { useHasToken } from '@/hooks/wishpool/useHasToken';

const NAV_LIST = [
{ label: 'WishPool 소개', href: PATH.INTRO },
Expand All @@ -14,15 +14,10 @@ const NAV_LIST = [
const NavMenu = () => {
const pathname = usePathname();
const router = useRouter();

const [token, setToken] = useState<string | null>(null);

useEffect(() => {
setToken(localStorage.getItem('accessToken'));
}, []);
const hasToken = useHasToken();

const handleNavClick = (href: string) => {
if (!token) router.push(PATH.LOGIN);
if (!hasToken) router.push(PATH.LOGIN);
else router.push(href);
};

Expand Down
Loading