Seems to be all working!!

This commit is contained in:
Luke Berndt
2023-04-02 22:27:36 -04:00
parent b8e60ab926
commit efe3794eee
10 changed files with 210 additions and 148 deletions

View File

@@ -15,25 +15,25 @@ import ResetPassword from "../User/ResetPassword"
import Terms from "../User/Terms"
const App = (params) => {
const {store} = params;
return (
<div>
<Navigation/>
<Routes>
<Route exact path="/" element={ <Restricted><Profile/></Restricted>} />
<Route path="/login" element={ <Login/>} />
<Route path="/register" element={ <Register/> } />
<Route path="/wait-confirm-email" element={ <WaitConfirmEmail/> } />
<Route path="/sent-confirm-email" element={ <SentConfirmEmail/> } />
<Route path="/send-reset-password" element={ <SendResetPassword/> } />
<Route path="/reset-password/:userId/:token" element={ <ResetPassword/> } />
<Route path="/confirm-email/:userId/:token" element={ <ConfirmEmail/> } />
<Route path="/terms" element={ <Restricted><Terms/></Restricted>} />
<Route path="/profile" element={ <Restricted><Profile/></Restricted>} />
<Route render={() => (<div>Miss</div>)} />
</Routes>
</div>
)
const { store } = params;
return (
<div>
<Navigation />
<Routes>
<Route exact path="/" element={<Restricted><Profile /></Restricted>} />
<Route path="/login" element={<Login />} />
<Route path="/register" element={<Register />} />
<Route path="/wait-confirm-email" element={<WaitConfirmEmail />} />
<Route path="/sent-confirm-email" element={<SentConfirmEmail />} />
<Route path="/send-reset-password" element={<SendResetPassword />} />
<Route path="/reset-password/:userId/:token" element={<ResetPassword />} />
<Route path="/confirm-email/:userId/:token" element={<ConfirmEmail />} />
<Route path="/terms" element={<Restricted><Terms /></Restricted>} />
<Route path="/profile" element={<Restricted><Profile /></Restricted>} />
<Route render={() => (<div>Miss</div>)} />
</Routes>
</div>
)
};
export default App

View File

@@ -1,32 +1,31 @@
// in src/restricted.js
import React, { useEffect} from "react";
import React, { useEffect } from "react";
import { useSelector, useDispatch } from 'react-redux'
import { authenticateUser } from "../features/user/userSlice";
import { authenticateUser } from "../features/user/userSlice";
import { useNavigate } from 'react-router-dom';
/**
* Higher-order component (HOC) to wrap restricted pages
*/
const Restricted = ({children }) => {
const Restricted = ({ children }) => {
const { authenticated, hasAuthenticated } = useSelector((state) => state.user);
const dispatch = useDispatch();
const navigate = useNavigate();
useEffect(() => {
dispatch(authenticateUser({}));
},[]);
}, []);
if (hasAuthenticated) {
if (authenticated) {
return children;;
}
else {
navigate("/list-systems")
}
}
return <div/>
return children;
}
else {
navigate("/login")
}
}
return <div />
};
export default Restricted