2024-02-28 21:49:44 +05:00
|
|
|
import { useEffect } from 'react'
|
2024-04-08 17:45:51 +05:00
|
|
|
import { Navigate, Route, Routes } from 'react-router-dom'
|
2024-12-20 15:25:02 +05:00
|
|
|
|
|
|
|
import { useAppSelector, useAuth } from './hooks'
|
|
|
|
|
2024-02-28 21:49:44 +05:00
|
|
|
import { MainLayout } from './layouts/Main'
|
2024-04-08 17:45:51 +05:00
|
|
|
import {
|
|
|
|
privateRoutes,
|
2024-07-26 13:15:14 +02:00
|
|
|
publicRoutes,
|
|
|
|
recursiveRouteRenderer
|
2024-11-18 17:29:46 +01:00
|
|
|
} from './routes/util'
|
2024-02-27 19:03:15 +05:00
|
|
|
|
2024-12-20 15:25:02 +05:00
|
|
|
import './App.scss'
|
|
|
|
|
2024-02-28 21:49:44 +05:00
|
|
|
const App = () => {
|
2024-12-20 15:25:02 +05:00
|
|
|
const { checkSession } = useAuth()
|
2025-01-31 19:32:28 +01:00
|
|
|
const isLoggedIn = useAppSelector((state) => state.auth?.loggedIn)
|
2024-02-28 21:49:44 +05:00
|
|
|
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
|
2024-12-20 15:25:02 +05:00
|
|
|
checkSession()
|
|
|
|
}, [checkSession])
|
2024-02-28 21:49:44 +05:00
|
|
|
|
2024-07-31 13:48:57 +02:00
|
|
|
// Hide route only if loggedIn and r.hiddenWhenLoggedIn are both true
|
|
|
|
const publicRoutesList = recursiveRouteRenderer(publicRoutes, (r) => {
|
2025-01-31 19:32:28 +01:00
|
|
|
return !isLoggedIn || !r.hiddenWhenLoggedIn
|
2024-07-26 13:15:14 +02:00
|
|
|
})
|
|
|
|
|
2024-07-31 13:48:57 +02:00
|
|
|
const privateRouteList = recursiveRouteRenderer(privateRoutes)
|
2024-07-26 13:15:14 +02:00
|
|
|
|
2024-02-27 19:03:15 +05:00
|
|
|
return (
|
2024-02-28 21:49:44 +05:00
|
|
|
<Routes>
|
|
|
|
<Route element={<MainLayout />}>
|
2024-07-26 13:15:14 +02:00
|
|
|
{publicRoutesList}
|
2025-01-31 19:32:28 +01:00
|
|
|
{privateRouteList}
|
|
|
|
<Route path="*" element={<Navigate to={'/'} />} />
|
2024-02-28 21:49:44 +05:00
|
|
|
</Route>
|
|
|
|
</Routes>
|
2024-02-27 19:03:15 +05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App
|