formatting and complete permission part of pages and removing _fencing page...
This commit is contained in:
29
src/core/middlewares/withPermission.js
Normal file
29
src/core/middlewares/withPermission.js
Normal file
@@ -0,0 +1,29 @@
|
||||
"use client";
|
||||
|
||||
import { Box, Typography } from "@mui/material";
|
||||
import { usePermissions } from "@/lib/hooks/usePermissions";
|
||||
|
||||
function WithPermission({ children, permission_name }) {
|
||||
const { data, error, isLoading } = usePermissions();
|
||||
|
||||
if (error || isLoading || !data || !permission_name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const hasPermission =
|
||||
permission_name.includes("all") || permission_name.some((permission) => data.includes(permission));
|
||||
|
||||
if (!hasPermission) {
|
||||
return (
|
||||
<Box sx={{ display: "flex", alignItems: "center", justifyContent: "center", height: "100%" }}>
|
||||
<Typography variant="h5" sx={{ letterSpacing: "2px", color: "error.main" }}>
|
||||
شما دسترسی لازم به این صفحه را ندارید
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
export default WithPermission;
|
||||
Reference in New Issue
Block a user