import React, { useState } from 'react' import { Button, EyeIcon, EyeOffIcon, Skeleton, WarningIcon } from 'ui' import { ChevronsUpDownIcon } from 'lucide-react' import { useParams } from 'common' import { useAPIKeysQuery } from 'data/api-keys/api-keys-query' import { SimpleCodeBlock } from 'ui/src/components/SimpleCodeBlock' import { useCheckPermissions, usePermissionsLoaded } from 'hooks/misc/useCheckPermissions' import { PermissionAction } from '@supabase/shared-types/out/constants' import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query' const frameworkOptions = ['React', 'Vue', 'Angular', 'Svelte'] // Add more as needed const QuickKeyCopyWrapper = () => { const [selectedFramework, setSelectedFramework] = useState('React') return (

Quick key copy

Choose your framework and paste the code into your environment file.

) } const QuickKeyCopyContent = ({ selectedFramework }: { selectedFramework: string }) => { const { ref: projectRef } = useParams() const { data: projectAPI, isLoading: isProjectApiLoading, error: projectApiError, } = useProjectSettingsV2Query({ projectRef: projectRef as string, }) const { data: apiKeysData, isLoading: isApiKeysLoading, error: apiKeysError, } = useAPIKeysQuery({ projectRef: projectRef as string, reveal: false, }) const isPermissionsLoading = !usePermissionsLoaded() const canReadAPIKeys = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, '*') const publishableApiKey = apiKeysData?.find(({ type }) => type === 'publishable')?.api_key const dataErrors = projectApiError || apiKeysError const permissionErrors = !canReadAPIKeys && !isPermissionsLoading if (isProjectApiLoading || isApiKeysLoading || isPermissionsLoading) { return (
) } const EmptyContainer = ({ children }: { children: React.ReactNode }) => { return (
{children}
) } // if (!canReadAPIKeys) { // return ( // //
// //

You do not have permission to read API Keys

//
//

// Please contact your project admin/owner to request access. //

//
// ) // } // TO DO : this needs to be changed to just if(error) // currently it's not working as API returns an error. if (dataErrors) { return (

Error loading Secret API Keys

{projectApiError?.message ?? apiKeysError?.message ?? 'Error: Failed to load API keys'}

) } const getEnvContent = () => { return ` NEXT_PUBLIC_SUPABASE_URL=${projectAPI?.app_config?.endpoint || ''} NEXT_PUBLIC_SUPABASE_PUBLISHABLE_API_KEY=${!canReadAPIKeys ? 'You do not have permission to read the Publishable API key' : publishableApiKey || ''} ` } return (
env
.env.local
{getEnvContent()}
) } export default QuickKeyCopyWrapper