mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-12 16:57:39 -05:00
Seems to be all working!!
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user