closer to working

This commit is contained in:
Luke Berndt
2023-03-26 09:27:05 -04:00
parent a5888e412c
commit 5875364502
17 changed files with 6932 additions and 27717 deletions

View File

@@ -27,22 +27,6 @@ const App = (params) => {
</Routes>
</div>
)
/*
return (
<div>
<NavigationContainer />
<Routes>
<Route path="/about" element={<About />} component={Restricted(About, store)} />
<Route path="/system/:shortName" component={Restricted(SystemContainer, store)} />
<Route path="/update-system/:shortName" component={Restricted(UpdateSystemContainer, store)} />
<Route path="/create-system" component={Restricted(CreateSystemContainer, store)} />
<Route path="/list-systems" component={Restricted(ListSystemsContainer, store)} />
<Route path="/" component={Restricted(ListSystemsContainer, store)} />
<Route render={() => (<div>Miss</div>)} />
</Routes>
</div>
)*/
};
export default App

View File

@@ -2,6 +2,7 @@
import React, { useEffect} from "react";
import { useSelector, useDispatch } from 'react-redux'
import { authenticateUser } from "../features/user/userSlice";
import { useNavigate } from 'react-router-dom';
/**
* Higher-order component (HOC) to wrap restricted pages
*/
@@ -9,14 +10,21 @@ import { authenticateUser } from "../features/user/userSlice";
const Restricted = ({children }) => {
const { authenticated, hasAuthenticated } = useSelector((state) => state.user);
const dispatch = useDispatch();
const navigate = useNavigate();
useEffect(() => {
dispatch(authenticateUser({}));
},[]);
if (authenticated) {
return children;;
}
if (hasAuthenticated) {
if (authenticated) {
return children;;
}
else {
navigate("/list-systems")
}
}
return <div/>
};