Skip to main content
Glama
GoogleButton.tsx1.96 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { Box } from '@mantine/core'; import type { GoogleCredentialResponse } from '@medplum/core'; import type { JSX } from 'react'; import { useEffect, useRef, useState } from 'react'; import { createScriptTag } from '../utils/script'; interface GoogleApi { readonly accounts: { id: { initialize: (args: any) => void; renderButton: (parent: HTMLElement, args: any) => void; }; }; } declare const google: GoogleApi; export interface GoogleButtonProps { readonly googleClientId?: string; readonly handleGoogleCredential: (response: GoogleCredentialResponse) => void; } export function GoogleButton(props: GoogleButtonProps): JSX.Element | null { const { googleClientId, handleGoogleCredential } = props; const parentRef = useRef<HTMLDivElement>(null); const [scriptLoaded, setScriptLoaded] = useState<boolean>(typeof google !== 'undefined'); const initializedRef = useRef(false); const buttonRenderedRef = useRef(false); useEffect(() => { if (typeof google === 'undefined') { createScriptTag('https://accounts.google.com/gsi/client', () => setScriptLoaded(true)); return; } if (!initializedRef.current) { google.accounts.id.initialize({ client_id: googleClientId, callback: handleGoogleCredential, }); initializedRef.current = true; } if (parentRef.current && !buttonRenderedRef.current) { google.accounts.id.renderButton(parentRef.current, { type: 'standard', logo_alignment: 'center', width: parentRef.current.clientWidth, }); buttonRenderedRef.current = true; } }, [googleClientId, scriptLoaded, handleGoogleCredential]); if (!googleClientId) { return null; } return <Box ref={parentRef} w="100%" h={40} display="flex" style={{ justifyContent: 'center' }} />; }

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