Skip to content

Commit

Permalink
Added isUserAllowedToAccessDelegationsRoutes in AuthGuard.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
martinaCampoli committed Dec 11, 2024
1 parent 61a1b98 commit d366a30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/layout/SideNav/hooks/useGetSideNavItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ const views = [
] as const

export function useGetSideNavItems() {
const { currentRoles, isSupport, isOrganizationAllowedToProduce } = AuthHooks.useJwt()
const { currentRoles, isSupport, isOrganizationAllowedToProduce, jwt } = AuthHooks.useJwt()

const { data: tenant } = TenantHooks.useGetActiveUserParty()

const isCertifier = isTenantCertifier(tenant)

const isPA = AuthHooks.useJwt().jwt?.externalId?.origin === 'IPA'
const isPA = jwt?.externalId?.origin === 'IPA'

return React.useMemo(() => {
/**
Expand Down
19 changes: 18 additions & 1 deletion src/router/components/RoutesWrapper/AuthGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,25 @@ export const AuthGuard: React.FC<AuthGuardProps> = ({

return isAuthorized && !isInBlacklist && !(isInProvidersRoutes && !canAccessProviderRoutes)
}

function isUserAllowedToAccessDelegationsRoutes() {
// The IsUserAllowedToAccessDelegationsRoutes method checks if the organization is a PA. Only a PA can access the delegations routes
const isPA = jwt?.externalId?.origin === 'IPA'
const delegationsRoutes: Array<RouteKey> = [
'DELEGATIONS',
'DELEGATION_DETAILS',
'CREATE_DELEGATION',
]
return isPA || !delegationsRoutes.includes(routeKey)
}

// JWT will be undefined just in case route is public.
if (jwt && (!isUserAllowedToAccessRoute() || !isUserAllowedToAccessCertifierRoutes())) {
if (
jwt &&
(!isUserAllowedToAccessRoute() ||
!isUserAllowedToAccessCertifierRoutes() ||
!isUserAllowedToAccessDelegationsRoutes())
) {
throw new ForbiddenError()
}

Expand Down

0 comments on commit d366a30

Please sign in to comment.