Skip to content

Commit ff69e82

Browse files
committed
refactor: publicroute 적용
1 parent bcc61e2 commit ff69e82

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

src/App.tsx

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { useAuthStore } from '@/store/authStore';
2-
import { Navigate, Route, Routes, useLocation } from 'react-router';
1+
import { Route, Routes, useLocation } from 'react-router';
32
import Layout from '@/layouts/Layout';
43
import Landing from '@/pages/landing/Landing';
54
import Modal from '@/components/Modal';
@@ -25,22 +24,16 @@ import KaKaoRedirection from '@/components/KaKaoRedirection';
2524
import { useSSE } from '@/hooks/useSSE';
2625
import { useYotube } from '@/hooks/useYoutube';
2726
import { useSpotifyAuth } from '@/hooks/useSpotifyAuth';
28-
import { useEffect } from 'react';
2927
import { useTokenExpired } from '@/hooks/useTokenRefresh';
3028
import UserProfile from '@/pages/user/UserProfile';
29+
import PublicRoute from '@/routes/PublicRoute';
3130

3231
function App() {
3332
const location = useLocation();
3433

35-
const { isAuthenticated } = useAuthStore();
3634
const { isRequestSendingSheetOpen, isRequestReceivingSheetOpen } = useSheetStore();
3735

38-
const spotifyAuth = useSpotifyAuth();
39-
useEffect(() => {
40-
if (isAuthenticated) {
41-
console.log('Spotify Auth Initialized:', spotifyAuth);
42-
}
43-
}, [isAuthenticated]);
36+
useSpotifyAuth();
4437

4538
useSSE(); // SSE연결
4639
useTokenExpired(); // 토큰 만료 체크
@@ -53,19 +46,11 @@ function App() {
5346
<AnimatedLayout>
5447
<Routes location={location}>
5548
<Route path="/" element={<Layout />}>
56-
<Route
57-
index
58-
element={isAuthenticated ? <Navigate to="/home" replace /> : <Landing />}
59-
/>
60-
61-
<Route
62-
path="/login"
63-
element={isAuthenticated ? <Navigate to="/home" replace /> : <Login />}
64-
/>
65-
<Route
66-
path="/signup"
67-
element={isAuthenticated ? <Navigate to="/home" replace /> : <SignUp />}
68-
/>
49+
<Route element={<PublicRoute />}>
50+
<Route index element={<Landing />} />
51+
<Route path="/login" element={<Login />} />
52+
<Route path="/signup" element={<SignUp />} />
53+
</Route>
6954

7055
{/* PrivateRoute 적용 */}
7156
<Route element={<PrivateRoute />}>

src/routes/PublicRoute.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { useAuthStore } from '@/store/authStore';
22
import { Navigate, Outlet } from 'react-router';
33

44
const PublicRoute = () => {
5-
65
const { isAuthenticated } = useAuthStore();
76

8-
return isAuthenticated ? <Navigate to="/" replace /> : <Outlet />;
7+
return isAuthenticated ? <Navigate to="/home" replace /> : <Outlet />;
98
};
109

1110
export default PublicRoute;

0 commit comments

Comments
 (0)