This commit is contained in:
Erik 2022-03-21 23:42:08 +02:00
parent e69c293f21
commit 580b15da00
No known key found for this signature in database
GPG Key ID: FEFF4B220DDF5589
3 changed files with 35 additions and 2 deletions

View File

@ -1,11 +1,28 @@
//import 'dotenv/config'
import './css/App.css'; 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 Home from './pages/Home';
import Media from './pages/Media'; 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() { function App() {
const [user, updateSession] = useLoginContext();
useEffect(() => {
fetchUser().then(user => {
if (user) setSession(user, user.accessToken);
else clearSession();
updateSession();
});
}, []);
return ( return (
<div className="app"> <div className="app">
@ -15,6 +32,7 @@ function App() {
<div className='flex-container'> <div className='flex-container'>
<NavLink className='navlink' to='/'>Home</NavLink> <NavLink className='navlink' to='/'>Home</NavLink>
<NavLink className='navlink' to='/media'>Media</NavLink> <NavLink className='navlink' to='/media'>Media</NavLink>
{user? <NavLink className='navlink' to='/panel' >Panel</NavLink> : null}
</div> </div>
</header> </header>
@ -26,6 +44,15 @@ function App() {
<Route exact path='/' element={<Home />} /> <Route exact path='/' element={<Home />} />
<Route exact path='/media' element={<Media />} /> <Route exact path='/media' element={<Media />} />
<Route exact path='/login' element={<LoginPage />} />
<Route
path='/panel'
element={
<PrivateRoute>
<Panel />
</PrivateRoute>
}
/>
</Routes> </Routes>

View File

@ -3,10 +3,13 @@ import ReactDOM from 'react-dom';
import './css/index.css'; import './css/index.css';
import App from './App'; import App from './App';
import reportWebVitals from './reportWebVitals'; import reportWebVitals from './reportWebVitals';
import { UserContext } from './Structures/UserContext';
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
<UserContext>
<App /> <App />
</UserContext>
</React.StrictMode>, </React.StrictMode>,
document.getElementById('root') document.getElementById('root')
); );

3
client/src/options.js Normal file
View File

@ -0,0 +1,3 @@
export default {
get domain() { return process.env.NODE_ENV === 'production' ? 'corgi.wtf' : 'localhost:4000'; }
};