sigit.io/src/App.tsx
SwiftHawk bd1e8417c1
All checks were successful
Release / build_and_release (push) Successful in 1m2s
feat: create signing request and send a DM to first signer with zip file url and encryption key
2024-04-08 17:45:51 +05:00

87 lines
2.2 KiB
TypeScript

import { useEffect } from 'react'
import { useSelector } from 'react-redux'
import { Navigate, Route, Routes } from 'react-router-dom'
import { AuthController, NostrController } from './controllers'
import { MainLayout } from './layouts/Main'
import {
appPrivateRoutes,
appPublicRoutes,
privateRoutes,
publicRoutes
} from './routes'
import { State } from './store/rootReducer'
import { getNsecBunkerDelegatedKey, saveNsecBunkerDelegatedKey } from './utils'
const App = () => {
const authState = useSelector((state: State) => state.auth)
useEffect(() => {
generateBunkerDelegatedKey()
const authController = new AuthController()
authController.checkSession()
}, [])
const generateBunkerDelegatedKey = () => {
const existingKey = getNsecBunkerDelegatedKey()
if (!existingKey) {
const nostrController = NostrController.getInstance()
const newDelegatedKey = nostrController.generateDelegatedKey()
saveNsecBunkerDelegatedKey(newDelegatedKey)
}
}
return (
<Routes>
<Route element={<MainLayout />}>
{authState?.loggedIn &&
privateRoutes.map((route, index) => (
<Route
key={route.path + index}
path={route.path}
element={route.element}
/>
))}
{publicRoutes.map((route, index) => {
if (authState?.loggedIn) {
if (!route.hiddenWhenLoggedIn) {
return (
<Route
key={route.path + index}
path={route.path}
element={route.element}
/>
)
}
} else {
return (
<Route
key={route.path + index}
path={route.path}
element={route.element}
/>
)
}
})}
<Route
path='*'
element={
<Navigate
to={
authState.loggedIn
? appPrivateRoutes.homePage
: appPublicRoutes.login
}
/>
}
/>
</Route>
</Routes>
)
}
export default App