GRAB X APOTEK X Hospital PORTAL
This commit is contained in:
@@ -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}/>;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user