import { useMemo } from 'react' import { InputVariants } from '@ui/components/shadcn/ui/input' import { useParams } from 'common' import CopyButton from 'components/ui/CopyButton' import { FormHeader } from 'components/ui/Forms/FormHeader' import { useAPIKeysQuery } from 'data/api-keys/api-keys-query' import { cn, EyeOffIcon, Input_Shadcn_, Skeleton, Tooltip, TooltipContent, TooltipTrigger, WarningIcon, } from 'ui' import { useApiKeysVisibility } from './hooks/useApiKeysVisibility' // to add in later with follow up PR // import CreatePublishableAPIKeyDialog from './CreatePublishableAPIKeyDialog' // to add in later with follow up PR // import ShowPublicJWTsDialogComposer from '../JwtSecrets/ShowPublicJWTsDialogComposer' export const PublishableAPIKeys = () => { const { ref: projectRef } = useParams() const { canReadAPIKeys, isLoading: isLoadingVisibility } = useApiKeysVisibility() const { data: apiKeysData, isLoading: isLoadingApiKeys, error, } = useAPIKeysQuery({ projectRef, reveal: false }, { enabled: canReadAPIKeys }) const publishableApiKeys = useMemo( () => apiKeysData?.filter(({ type }) => type === 'publishable') ?? [], [apiKeysData] ) // The default publisahble key will always be the first one const apiKey = publishableApiKeys[0] return (
Publishable key
{!canReadAPIKeys ? 'You need additional permissions to copy publishable keys' : isLoadingApiKeys ? 'Loading permissions...' : 'Copy publishable key'}
{error && canReadAPIKeys ? (
Failed to load publishable key: {error?.message}
) : (
The publishable key can be safely shared publicly
)}
) } const ApiKeyInput = () => { const { ref: projectRef } = useParams() const { canReadAPIKeys, isLoading: isPermissionsLoading } = useApiKeysVisibility() const { data: apiKeysData, isLoading: isApiKeysLoading, error, } = useAPIKeysQuery({ projectRef, reveal: false }, { enabled: canReadAPIKeys }) const publishableApiKeys = useMemo( () => apiKeysData?.filter(({ type }) => type === 'publishable') ?? [], [apiKeysData] ) // The default publisahble key will always be the first one const apiKey = publishableApiKeys[0] const baseClasses = 'flex-1 grow gap-1 rounded-full min-w-0 max-w-[200px] sm:max-w-[300px] md:max-w-[400px] lg:min-w-[24rem]' const size = 'tiny' if (!canReadAPIKeys && !isPermissionsLoading) { return (
You do not have permission to read API Key
) } if (isApiKeysLoading || isPermissionsLoading) { return (
) } if (error) { return (
Failed to load publishable key
) } return ( ) }