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
10 changes: 10 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import Intro from './pages/external/Intro.jsx';
import Leaders from './pages/external/Leaders.jsx';
import Portfolio from './pages/external/Portfolio.jsx';

import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

function App() {
return (
<>
Expand All @@ -44,6 +47,13 @@ function App() {
<Route path="/mypage" element={<Mypage />} />
</Route>
</Routes>
<ToastContainer
position="top-center"
autoClose={2000}
hideProgressBar={false}
pauseOnHover
theme="light"
/>
</>
);
}
Expand Down
125 changes: 95 additions & 30 deletions frontend/src/components/Sidebar.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { NavLink, useNavigate, useLocation } from 'react-router-dom';
import styles from './Sidebar.module.css';
import { useState } from 'react';
import { api } from '../utils/axios';
import { toast } from 'react-toastify';

const Sidebar = ({ isOpen, isRoot }) => {
const navigate = useNavigate();
Expand All @@ -23,6 +25,32 @@ const Sidebar = ({ isOpen, isRoot }) => {
const [selectedBoard, setSelectedBoard] = useState(
currentBoard?.name || '전체 게시판'
);
const [isLoggedIn, setIsLoggedIn] = useState(
!!localStorage.getItem('accessToken')
);
Comment thread
DongEun02 marked this conversation as resolved.

const logout = async () => {
const accessToken = localStorage.getItem('accessToken');
try {
await api.post(
'/api/auth/logout',
{},
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
);
} catch {
toast.error('오류가 발생했습니다.');
} finally {
localStorage.removeItem('accessToken');
localStorage.removeItem('refreshToken');
setIsLoggedIn(false);
navigate('/');
toast.success('로그아웃 되었습니다.');
}
};
Comment thread
DongEun02 marked this conversation as resolved.

return (
<div>
Expand Down Expand Up @@ -124,36 +152,73 @@ const Sidebar = ({ isOpen, isRoot }) => {
<div className={styles['menu-section']}>
<span className={styles['menu-title']}>계정</span>
<ul>
<li>
<NavLink
to="/mypage"
className={({ isActive }) =>
isActive ? styles['active-link'] : styles['inactive-link']
}
>
마이페이지
</NavLink>
</li>
<li>
<NavLink
to="/login"
className={({ isActive }) =>
isActive ? styles['active-link'] : styles['inactive-link']
}
>
로그인
</NavLink>
</li>
<li>
<NavLink
to="/signup"
className={({ isActive }) =>
isActive ? styles['active-link'] : styles['inactive-link']
}
>
회원가입
</NavLink>
</li>
{isLoggedIn ? (
<>
<li>
<NavLink
to="/mypage"
className={({ isActive }) =>
isActive
? styles['active-link']
: styles['inactive-link']
}
>
마이페이지
</NavLink>
</li>

<li>
<NavLink
to="/"
className={styles['inactive-link']}
onClick={logout}
>
로그아웃
</NavLink>
</li>
</>
) : (
<>
<li>
<NavLink
to="/mypage"
className={({ isActive }) =>
isActive
? styles['active-link']
: styles['inactive-link']
}
>
마이페이지
</NavLink>
</li>

<li>
<NavLink
to="/login"
className={({ isActive }) =>
isActive
? styles['active-link']
: styles['inactive-link']
}
>
로그인
</NavLink>
</li>

<li>
<NavLink
to="/signup"
className={({ isActive }) =>
isActive
? styles['active-link']
: styles['inactive-link']
}
>
회원가입
</NavLink>
</li>
</>
)}
Comment thread
DongEun02 marked this conversation as resolved.
</ul>
</div>
</nav>
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/hooks/useAuthGuard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { toast } from 'react-toastify';

export const useAuthGuard = () => {
const nav = useNavigate();

useEffect(() => {
if (!localStorage.getItem('accessToken')) {
toast.error('로그인 후 이용하실 수 있습니다.');
nav('/login');
}
}, [nav]);
};
3 changes: 3 additions & 0 deletions frontend/src/pages/Mypage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import styles from './Mypage.module.css';
import MyPageMenu from '../components/mypage/MyPageMenu';
import ProfileCard from '../components/mypage/ProfileCard';
import AccountSecurity from '../components/mypage/AccountSecurity';
import { useAuthGuard } from '../hooks/useAuthGuard';

const Mypage = () => {
useAuthGuard();

return (
<div className={styles.container}>
<h1 className={styles.title}>마이페이지</h1>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/StockGame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import styles from './StockGame.module.css';
import Betting from '../components/stockgame/Betting';
import BettingHistory from '../components/stockgame/BettingHistory';
import { useState } from 'react';
import { useAuthGuard } from '../hooks/useAuthGuard';

const StockGame = () => {
const [active, setactive] = useState('progress');
const [lastGame, setLastGame] = useState('weekly');

useAuthGuard();

return (
<div className={styles['stock-game']}>
<h1 className={styles['title']}>주식베팅</h1>
Expand Down