check if user has an org first

This commit is contained in:
Nate Kelley 2025-01-23 09:26:23 -07:00
parent db43289d71
commit de85b20627
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
1 changed files with 11 additions and 4 deletions

View File

@ -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
);
};