protect DU routes
This commit is contained in:
1 parent
4f16d8140e
commit
7b4f78132d
2 files changed
+47
-3
No files matched your search
@@ -0,0 +1,30 @@
|
|||||||
|
import { Navigate } from "react-router-dom";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} props - The props passed to the ProtectedDistributedUptimeRoute component.
|
||||||
|
* @param {React.ReactNode} props.children - The children to render if the user is authenticated.
|
||||||
|
* @returns {React.ReactElement} The children wrapped in a protected route or a redirect to the login page.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const ProtectedDistributedUptimeRoute = ({ children }) => {
|
||||||
|
const distributedUptimeEnabled = useSelector(
|
||||||
|
(state) => state.ui.distributedUptimeEnabled
|
||||||
|
);
|
||||||
|
|
||||||
|
return distributedUptimeEnabled === true ? (
|
||||||
|
children
|
||||||
|
) : (
|
||||||
|
<Navigate
|
||||||
|
to="/uptime"
|
||||||
|
replace
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
ProtectedDistributedUptimeRoute.propTypes = {
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProtectedDistributedUptimeRoute;
|
||||||
@@ -48,6 +48,7 @@ import Settings from "../Pages/Settings";
|
|||||||
import Maintenance from "../Pages/Maintenance";
|
import Maintenance from "../Pages/Maintenance";
|
||||||
|
|
||||||
import ProtectedRoute from "../Components/ProtectedRoute";
|
import ProtectedRoute from "../Components/ProtectedRoute";
|
||||||
|
import ProtectedDistributedUptimeRoute from "../Components/ProtectedDistributedUptimeRoute";
|
||||||
import CreateNewMaintenanceWindow from "../Pages/Maintenance/CreateMaintenance";
|
import CreateNewMaintenanceWindow from "../Pages/Maintenance/CreateMaintenance";
|
||||||
import withAdminCheck from "../Components/HOC/withAdminCheck";
|
import withAdminCheck from "../Components/HOC/withAdminCheck";
|
||||||
|
|
||||||
@@ -86,15 +87,28 @@ const Routes = () => {
|
|||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/distributed-uptime"
|
path="/distributed-uptime"
|
||||||
element={<DistributedUptimeMonitors />}
|
element={
|
||||||
|
<ProtectedDistributedUptimeRoute>
|
||||||
|
<DistributedUptimeMonitors />{" "}
|
||||||
|
</ProtectedDistributedUptimeRoute>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="/distributed-uptime/create"
|
path="/distributed-uptime/create"
|
||||||
element={<CreateDistributedUptime />}
|
element={
|
||||||
|
<ProtectedDistributedUptimeRoute>
|
||||||
|
<CreateDistributedUptime />
|
||||||
|
</ProtectedDistributedUptimeRoute>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/distributed-uptime/:monitorId"
|
path="/distributed-uptime/:monitorId"
|
||||||
element={<DistributedUptimeDetails />}
|
element={
|
||||||
|
<ProtectedDistributedUptimeRoute>
|
||||||
|
<DistributedUptimeDetails />
|
||||||
|
</ProtectedDistributedUptimeRoute>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="pagespeed"
|
path="pagespeed"
|
||||||
|
|||||||
Reference in new issue
Block a user