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 (
@@ -15,6 +32,7 @@ function App() {
Home Media + {user? Panel : null}
@@ -26,6 +44,15 @@ function App() { } /> } /> + } /> + + + + } + /> diff --git a/client/src/index.js b/client/src/index.js index 1d5fcf5..ec1a4d7 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -3,10 +3,13 @@ import ReactDOM from 'react-dom'; import './css/index.css'; import App from './App'; import reportWebVitals from './reportWebVitals'; +import { UserContext } from './Structures/UserContext'; ReactDOM.render( - + + + , document.getElementById('root') ); diff --git a/client/src/options.js b/client/src/options.js new file mode 100644 index 0000000..8926fa6 --- /dev/null +++ b/client/src/options.js @@ -0,0 +1,3 @@ +export default { + get domain() { return process.env.NODE_ENV === 'production' ? 'corgi.wtf' : 'localhost:4000'; } +}; \ No newline at end of file