From e978a1130a7d839d1b7bcdcebb8a0b9f3b4542cf Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 9 Aug 2024 09:20:35 +0700 Subject: [PATCH] Create App.tsx --- projects/pi-nexus-iam/containers/App.tsx | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 projects/pi-nexus-iam/containers/App.tsx 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;