import { PermissionAction } from '@supabase/shared-types/out/constants' 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 { useCheckPermissions, usePermissionsLoaded } from 'hooks/misc/useCheckPermissions' import { Link } from 'lucide-react' import { useMemo } from 'react' import { cn, EyeOffIcon, Input_Shadcn_, Skeleton, WarningIcon } from 'ui' import QuickKeyCopyWrapper from './QuickKeyCopy' // to add in later with follow up PR // import CreatePublishableAPIKeyModal from './CreatePublishableAPIKeyModal' // 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 isPermissionsLoading = !usePermissionsLoaded() const canReadAPIKeys = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, '*') // The default publisahble key will always be the first one const apiKey = publishableApiKeys[0] return (
Default publishable key
{error && canReadAPIKeys ? (
Failed to load publishable key: {error?.message}
) : (
Publishable key can be safely shared in public
)}
Show Supabase Url
{/* */} {/* @mildtomato - To add in later with follow up PR */} {/* */}
{/* */}
) } function 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 isPermissionsLoading = !usePermissionsLoaded() const canReadAPIKeys = useCheckPermissions(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-[300px] truncate' 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 ( ) }