From de85b20627996768c575879f48c3f0073ad8d87d Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Thu, 23 Jan 2025 09:26:23 -0700 Subject: [PATCH] check if user has an org first --- web/src/context/Users/helpers.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 ); };