app
This commit is contained in:
parent
e69c293f21
commit
580b15da00
@ -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 (
|
||||
<div className="app">
|
||||
|
||||
@ -15,6 +32,7 @@ function App() {
|
||||
<div className='flex-container'>
|
||||
<NavLink className='navlink' to='/'>Home</NavLink>
|
||||
<NavLink className='navlink' to='/media'>Media</NavLink>
|
||||
{user? <NavLink className='navlink' to='/panel' >Panel</NavLink> : null}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@ -26,6 +44,15 @@ function App() {
|
||||
|
||||
<Route exact path='/' element={<Home />} />
|
||||
<Route exact path='/media' element={<Media />} />
|
||||
<Route exact path='/login' element={<LoginPage />} />
|
||||
<Route
|
||||
path='/panel'
|
||||
element={
|
||||
<PrivateRoute>
|
||||
<Panel />
|
||||
</PrivateRoute>
|
||||
}
|
||||
/>
|
||||
|
||||
</Routes>
|
||||
|
||||
|
@ -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(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
<UserContext>
|
||||
<App />
|
||||
</UserContext>
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
|
3
client/src/options.js
Normal file
3
client/src/options.js
Normal file
@ -0,0 +1,3 @@
|
||||
export default {
|
||||
get domain() { return process.env.NODE_ENV === 'production' ? 'corgi.wtf' : 'localhost:4000'; }
|
||||
};
|
Loading…
Reference in New Issue
Block a user