diff --git a/web/src/context/Users/helpers.ts b/web/src/context/Users/helpers.ts index 16bc93f91..4b5697694 100644 --- a/web/src/context/Users/helpers.ts +++ b/web/src/context/Users/helpers.ts @@ -1,9 +1,16 @@ import { BusterOrganizationRole, BusterUserResponse } from '@/api/buster_rest'; -export const checkIfUserIsAdmin = (userInfo?: BusterUserResponse | null) => { +export const checkIfUserIsAdmin = (userInfo?: BusterUserResponse | null): boolean => { + if (!userInfo) return false; + + const userOrganization = userInfo?.organizations?.[0]; + + if (!userOrganization) return false; + + const userRole = userOrganization.role; + return ( - !!userInfo && - (userInfo.organizations[0].role === BusterOrganizationRole.DATA_ADMIN || - userInfo.organizations[0].role === BusterOrganizationRole.WORKSPACE_ADMIN) + userRole === BusterOrganizationRole.DATA_ADMIN || + userRole === BusterOrganizationRole.WORKSPACE_ADMIN ); };