Skip to main content
Glama
admin.ts1.68 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { normalizeErrorString } from '@medplum/core'; import type { MedplumClient } from '@medplum/core'; import { useMedplum } from '@medplum/react'; import { useEffect, useState } from 'react'; /** * Checks if the current user is an admin by examining their ProjectMembership. * * @param medplum - The Medplum client instance * @returns A Promise that resolves to a boolean indicating whether the user is an admin */ export async function isUserAdmin(medplum: MedplumClient): Promise<boolean> { try { // Get the current user's profile const membership = medplum.getProjectMembership(); return membership?.admin ?? false; } catch (error) { console.error('Error checking admin status:', normalizeErrorString(error)); return false; } } /** * React hook that provides the admin status of the current user. * * @returns An object containing the admin status and loading state */ export function useAdminStatus(): { isAdmin: boolean; loading: boolean } { const medplum = useMedplum(); const [isAdminUser, setIsAdminUser] = useState<boolean>(false); const [loading, setLoading] = useState<boolean>(true); useEffect(() => { const checkAdminStatus = async (): Promise<void> => { const adminStatus = await isUserAdmin(medplum); setIsAdminUser(adminStatus); setLoading(false); }; checkAdminStatus().catch((error) => { console.error('Error checking admin status:', normalizeErrorString(error)); setLoading(false); }); }, [medplum]); return { isAdmin: isAdminUser, loading }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/medplum/medplum'

If you have feedback or need assistance with the MCP directory API, please join our Discord server