diff --git a/projects/pi-nexus-iam/containers/App.tsx b/projects/pi-nexus-iam/containers/App.tsx new file mode 100644 index 000000000..208799884 --- /dev/null +++ b/projects/pi-nexus-iam/containers/App.tsx @@ -0,0 +1,51 @@ +import React, { useState, useEffect, useContext } from 'react'; +import { BrowserRouter, Route, Switch, Redirect } from 'react-router-dom'; +import { ThemeProvider } from 'styled-components'; +import { ToastContainer } from 'react-toastify'; +import 'react-toastify/dist/ReactToastify.css'; +import { AuthContext } from '../contexts/AuthContext'; +import { theme } from '../styles/theme'; +import { GlobalStyle } from '../styles/global'; +import Login from '../components/Login'; +import Dashboard from '../components/Dashboard'; +import NotFound from '../components/NotFound'; + +const App: React.FC = () => { + const { accessToken, refreshToken, logout } = useContext(AuthContext); + const [isAuthenticated, setIsAuthenticated] = useState(false); + + useEffect(() => { + if (accessToken && refreshToken) { + setIsAuthenticated(true); + } else { + setIsAuthenticated(false); + } + }, [accessToken, refreshToken]); + + const handleLogout = () => { + logout(); + setIsAuthenticated(false); + }; + + return ( + + + + + + + {isAuthenticated ? : } + + + {isAuthenticated ? : } + + + + + + + + ); +}; + +export default App;