sigit.io/src/App.tsx

49 lines
1.3 KiB
TypeScript
Raw Normal View History

import { useEffect } from 'react'
import { Navigate, Route, Routes } from 'react-router-dom'
import { useAppSelector, useAuth } from './hooks'
import { MainLayout } from './layouts/Main'
import {
privateRoutes,
publicRoutes,
recursiveRouteRenderer
} from './routes/util'
2024-02-27 19:03:15 +05:00
import './App.scss'
const App = () => {
const { checkSession } = useAuth()
const isLoggedIn = useAppSelector((state) => state.auth?.loggedIn)
useEffect(() => {
2024-05-29 17:03:00 +03:00
if (window.location.hostname === '0.0.0.0') {
2024-05-29 17:06:47 +03:00
// A change of the host is needed to make library available in windows object
2024-05-29 17:08:38 +03:00
// the app can't encrypt files without the crypto library
// which is only available on https or localhost
2024-05-29 17:03:00 +03:00
window.location.hostname = 'localhost'
}
checkSession()
}, [checkSession])
// Hide route only if loggedIn and r.hiddenWhenLoggedIn are both true
const publicRoutesList = recursiveRouteRenderer(publicRoutes, (r) => {
return !isLoggedIn || !r.hiddenWhenLoggedIn
})
const privateRouteList = recursiveRouteRenderer(privateRoutes)
2024-02-27 19:03:15 +05:00
return (
<Routes>
<Route element={<MainLayout />}>
{publicRoutesList}
{privateRouteList}
<Route path="*" element={<Navigate to={'/'} />} />
</Route>
</Routes>
2024-02-27 19:03:15 +05:00
)
}
export default App