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 ( }> {authState?.loggedIn && privateRoutes.map((route, index) => ( ))} {publicRoutes.map((route, index) => { if (authState?.loggedIn) { if (!route.hiddenWhenLoggedIn) { return ( ) } } else { return ( ) } })} } /> ) } export default App