diff --git a/client/src/App.js b/client/src/App.js index 3bb5da1..c8cb79e 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,11 +1,28 @@ +//import 'dotenv/config' import './css/App.css'; -import { BrowserRouter, Routes, Route, NavLink, Redirect } from 'react-router-dom'; +import { BrowserRouter, Routes, Route, NavLink } from 'react-router-dom'; +import React, { useEffect } from 'react'; import Home from './pages/Home'; import Media from './pages/Media'; +import LoginPage from './pages/Login'; +import Panel from './pages/Panel'; +import { clearSession, fetchUser, setSession } from './util/Util'; +import { PrivateRoute } from './Routes/Private'; +import { useLoginContext } from './Structures/UserContext'; function App() { + const [user, updateSession] = useLoginContext(); + + useEffect(() => { + fetchUser().then(user => { + if (user) setSession(user, user.accessToken); + else clearSession(); + updateSession(); + }); + }, []); + return (