snowballtools-base/packages/frontend/src/App.tsx

85 lines
1.9 KiB
TypeScript
Raw Normal View History

import { useEffect } from 'react';
2024-04-11 23:10:39 +00:00
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
2024-04-11 23:10:39 +00:00
import Projects from './pages/org-slug';
import Settings from './pages/org-slug/Settings';
import {
projectsRoutesWithSearch,
projectsRoutesWithoutSearch,
2024-04-11 23:10:39 +00:00
} from './pages/org-slug/projects/routes';
import ProjectSearchLayout from './layouts/ProjectSearch';
import Index from './pages';
2024-04-21 23:02:42 +00:00
import AuthPage from './pages/AuthPage';
2024-04-11 23:10:39 +00:00
import { DashboardLayout } from './pages/org-slug/layout';
2024-04-21 23:02:42 +00:00
import Web3Provider from 'context/Web3Provider';
import { BASE_URL } from 'utils/constants';
const router = createBrowserRouter([
{
2024-04-11 23:10:39 +00:00
path: ':orgSlug',
element: <DashboardLayout />,
children: [
{
element: <ProjectSearchLayout />,
children: [
{
2024-04-11 23:10:39 +00:00
path: '',
element: <Projects />,
},
{
2024-04-11 23:10:39 +00:00
path: 'projects',
children: projectsRoutesWithSearch,
},
],
},
{
2024-04-11 23:10:39 +00:00
path: 'settings',
element: <Settings />,
},
{
2024-04-11 23:10:39 +00:00
path: 'projects',
children: projectsRoutesWithoutSearch,
},
],
},
{
2024-04-11 23:10:39 +00:00
path: '/',
element: <Index />,
},
{
2024-04-11 23:10:39 +00:00
path: '/login',
2024-04-21 23:02:42 +00:00
element: <AuthPage />,
},
]);
function App() {
2024-04-21 23:02:42 +00:00
// Hacky way of checking session
// TODO: Handle redirect backs
useEffect(() => {
fetch(`${BASE_URL}/auth/session`, {
2024-04-21 23:02:42 +00:00
credentials: 'include',
}).then((res) => {
const path = window.location.pathname;
2024-04-21 23:02:42 +00:00
if (res.status !== 200) {
localStorage.clear();
if (path !== '/login') {
2024-04-21 23:02:42 +00:00
window.location.pathname = '/login';
}
} else {
if (path === '/login') {
window.location.pathname = '/';
}
2024-04-21 23:02:42 +00:00
}
});
}, []);
return (
<Web3Provider>
2024-04-24 02:10:20 +00:00
<RouterProvider router={router} />
2024-04-21 23:02:42 +00:00
</Web3Provider>
);
}
export default App;