import { PermissionAction } from '@supabase/shared-types/out/constants' import { useMemo } from 'react' import { useParams } from 'common' import { FormHeader } from 'components/ui/Forms/FormHeader' import { useAPIKeysQuery } from 'data/api-keys/api-keys-query' import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions' import { Card, CardContent, EyeOffIcon, Skeleton, WarningIcon } from 'ui' import { ScaffoldSection } from 'components/layouts/Scaffold' import { Input } from 'ui-patterns/DataInputs/Input' import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout' // 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 } = useAsyncCheckPermissions( PermissionAction.TENANT_SQL_ADMIN_WRITE, '*' ) // The default publisahble key will always be the first one const apiKey = publishableApiKeys[0] return ( {isLoadingApiKeys || isPermissionsLoading ? (
) : !canReadAPIKeys ? (
You do not have permission to read API Key
) : error ? (
Failed to load publishable key
) : ( )}
) }