import { PermissionAction } from '@supabase/shared-types/out/constants' 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 { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions' import { cn, EyeOffIcon, Input_Shadcn_, Skeleton, WarningIcon } from 'ui' // 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 { data: apiKeysData, isLoading: isLoadingApiKeys, error, } = useAPIKeysQuery({ projectRef, reveal: false }) const publishableApiKeys = useMemo( () => apiKeysData?.filter(({ type }) => type === 'publishable') ?? [], [apiKeysData] ) const { can: canReadAPIKeys, isLoading: isPermissionsLoading } = useAsyncCheckProjectPermissions( PermissionAction.TENANT_SQL_ADMIN_WRITE, '*' ) // The default publisahble key will always be the first one const apiKey = publishableApiKeys[0] return (
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 { data: apiKeysData, isLoading: isApiKeysLoading, error, } = useAPIKeysQuery({ projectRef, reveal: false }) const publishableApiKeys = useMemo( () => apiKeysData?.filter(({ type }) => type === 'publishable') ?? [], [apiKeysData] ) const { can: canReadAPIKeys, isLoading: isPermissionsLoading } = useAsyncCheckProjectPermissions( PermissionAction.TENANT_SQL_ADMIN_WRITE, '*' ) // 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 (isApiKeysLoading || isPermissionsLoading) { return (
) } if (!canReadAPIKeys) { return (
You do not have permission to read API Key
) } if (error) { return (
Failed to load publishable key
) } return ( ) }