role_middleware

This commit is contained in:
Yasiu1376
2023-07-24 14:37:43 +03:30
parent c149c697ea
commit 87023c0edc
8 changed files with 86 additions and 24 deletions

View File

@@ -0,0 +1,43 @@
import { NextLinkComposed } from "@/core/components/LinkRouting";
import Message from "@/core/components/Messages";
import useUser from "@/lib/app/hooks/useUser";
import { Button, Typography } from "@mui/material";
import { useTranslations } from "next-intl";
const RolePermission = ({ children, requiredPermissions }) => {
const { user } = useUser();
const t = useTranslations();
const hasPermission = requiredPermissions.some((permission) =>
user?.role?.includes(permission)
);
if (!hasPermission) {
return (
<Message
text={
<Typography sx={{ textAlign: "center" }}>
{t("Permission.typography_you_dont_have_access")}
</Typography>
}
actions={
<>
<Button
variant="contained"
component={NextLinkComposed}
to={{
pathname: "/dashboard",
}}
>
{t("Permission.button_back_dashboard")}
</Button>
</>
}
/>
);
}
return <>{children}</>;
};
export default RolePermission;