Skip to content

Commit

Permalink
feat: 토큰 검사 레이아웃 구현
Browse files Browse the repository at this point in the history
토큰 검사를 주기적으로 해야되는 페이지를 감싸는 레이아웃을 만들었습니다.
토큰 검사는 일단 30분에 한 번 동작하도록 만들었습니다.
  • Loading branch information
JeonDoGyun committed Oct 30, 2023
1 parent 5a63b40 commit c67c4ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SignupPage from 'pages/signUp/SignupPage';
import UrgentListPage from 'pages/profileList/urgentList/UrgentListPage';
import UpdatePage from 'pages/update/UpdatePage';
import HomePage from 'pages/home/HomePage';
import ValidateCheckLayout from 'layouts/ValidateCheckLayout';

const queryClient = new QueryClient({
defaultOptions: {
Expand All @@ -25,18 +26,21 @@ function App() {
<QueryClientProvider client={queryClient}>
<RecoilRoot>
<BrowserRouter>
<Routes>
<ValidateCheckLayout>
{/* 토큰 검사가 필요한 페이지에만 검사 */}
<Route path="/" element={<HomePage />} />
<Route path="/pet/:id" element={<DetailPetPage />} />
<Route path="/profile" element={<ProfileListPage />} />
<Route path="/shelter/:id/:page" element={<ShelterInfoPage />} />
<Route path="/profile/urgent/:page" element={<UrgentListPage />} />
<Route path="/profile/new/:page" element={<NewListPage />} />
<Route path="/register" element={<RegisterPage />} />
<Route path="/login" element={<LoginPage />} />
<Route path="/signup" element={<SignupPage />} />
<Route path="/find-shelter" element={<MapPage />} />
<Route path="/pet-update/:id" element={<UpdatePage />} />
</ValidateCheckLayout>
<Routes>
<Route path="/login" element={<LoginPage />} />
<Route path="/signup" element={<SignupPage />} />
</Routes>
</BrowserRouter>
</RecoilRoot>
Expand Down
20 changes: 20 additions & 0 deletions src/layouts/ValidateCheckLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { validateExpiredToken } from 'commons/cookie/getUser';
import React, { useEffect } from 'react';
import { Routes } from 'react-router-dom';

interface LayoutProps {
children: React.ReactNode;
}

const ValidateCheckLayout: React.FC<LayoutProps> = ({ children }) => {
useEffect(() => {
validateExpiredToken();
const intervalId = setInterval(validateExpiredToken, 60000 * 30); // 30분에 한 번

return () => clearInterval(intervalId);
}, []);

return <Routes>{children}</Routes>;
};

export default ValidateCheckLayout;

0 comments on commit c67c4ec

Please sign in to comment.