import { PermissionAction } from '@supabase/shared-types/out/constants' import { useParams } from 'common' import { Copy } from 'lucide-react' import { useEffect, useState } from 'react' import { Button, Input, copyToClipboard } from 'ui' import { getKeys, useAPIKeysQuery } from 'data/api-keys/api-keys-query' import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query' import { useSendEventMutation } from 'data/telemetry/send-event-mutation' import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions' import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization' import ContentSnippet from '../ContentSnippet' import { DOCS_CONTENT } from '../ProjectAPIDocs.constants' import type { ContentProps } from './Content.types' export const Introduction = ({ showKeys, language, apikey, endpoint }: ContentProps) => { const { ref } = useParams() const { can: canReadAPIKeys } = useAsyncCheckPermissions(PermissionAction.SECRETS_READ, '*') const { data: apiKeys } = useAPIKeysQuery({ projectRef: ref }, { enabled: canReadAPIKeys }) const { data } = useProjectSettingsV2Query({ projectRef: ref }) const { data: org } = useSelectedOrganizationQuery() const { mutate: sendEvent } = useSendEventMutation() const [copied, setCopied] = useState<'anon' | 'service'>() useEffect(() => { if (copied !== undefined) setTimeout(() => setCopied(undefined), 2000) }, [copied]) const { anonKey, serviceKey } = getKeys(apiKeys) const anonApiKey = anonKey?.api_key const serviceApiKey = serviceKey?.api_key ?? 'SUPABASE_CLIENT_SERVICE_KEY' return ( <>

Project URL

Client API key

} onClick={() => { setCopied('anon') copyToClipboard(anonApiKey ?? 'SUPABASE_CLIENT_ANON_KEY') sendEvent({ action: 'api_docs_code_copy_button_clicked', properties: { title: 'Client API key', selectedLanguage: language, }, groups: { project: ref ?? 'Unknown', organization: org?.slug ?? 'Unknown', }, }) }} > {copied === 'anon' ? 'Copied' : 'Copy'} , ]} />

Service key

This key has the ability to bypass Row Level Security.{' '} Never share it publicly.

} actions={[ , ]} />
) }