GRAB X APOTEK X Hospital PORTAL

This commit is contained in:
ivan-sim
2024-10-03 16:14:11 +07:00
parent 15138f7edf
commit 0758a70434
19 changed files with 2107 additions and 49 deletions

View File

@@ -13,8 +13,14 @@ type GuestGuardProps = {
export default function GuestGuard({ children }: GuestGuardProps) {
const { isAuthenticated } = useAuth();
if (isAuthenticated) {
const {user} = useAuth();
const formattedRoleName = user?.role.name;
if((formattedRoleName === 'admin-apotek' || formattedRoleName === 'cs-lms') && isAuthenticated)
{
return <Navigate to={'/prescription-orders'} replace={true}/>;
}
if(formattedRoleName === 'hospital-admin)
{
return <Navigate to={'/dashboard'} replace={true}/>;
}

View File

@@ -1,5 +1,7 @@
import { ReactNode } from 'react';
import { Container, Alert, AlertTitle } from '@mui/material';
import useAuth from '@/hooks/useAuth';
import Page404 from '@/pages/Page404';
// ----------------------------------------------------------------------
@@ -9,9 +11,10 @@ type RoleBasedGuardProp = {
};
const useCurrentRole = () => {
// Logic here to get current user role
const role = 'admin';
return role;
// Fetch the role from useAuth
const { user } = useAuth();
const formattedRoleName = user?.role.name || ''; // Default to empty string if role is undefined
return formattedRoleName;
};
export default function RoleBasedGuard({ accessibleRoles, children }: RoleBasedGuardProp) {