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

83 lines
1.8 KiB
TypeScript
Raw Normal View History

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 { useEffect } from 'react';
import Web3Provider from 'context/Web3Provider';
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 />,
},
{
path: '/signup',
element: <AuthPage />,
},
]);
function App() {
2024-04-21 23:02:42 +00:00
// Hacky way of checking session
// TODO: Handle redirect backs
useEffect(() => {
fetch(`${import.meta.env.VITE_SERVER_URL}/auth/session`, {
credentials: 'include',
}).then((res) => {
if (res.status !== 200) {
localStorage.clear();
2024-04-24 02:10:20 +00:00
const path = window.location.pathname;
if (path !== '/login' && path !== '/signup') {
2024-04-21 23:02:42 +00:00
window.location.pathname = '/login';
}
}
});
}, []);
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;