mirror of
https://github.com/supabase/supabase.git
synced 2026-09-10 20:10:31 +08:00
This PR removes all `paths` in `tsconfig.json` for all apps and packages. They were added previosly because some of the components had a `_Shadcn` suffix because of an ongoing migration. How that the migration is done, the paths can be removed. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Standardized shared UI component, utility, and icon imports across design-system examples and application screens. * Simplified shared component access and project configuration. * Added shared access to anchor-link helpers and animation styles. * **Compatibility** * Updated component exports and imports without changing existing behavior. * No changes to user-facing workflows, screens, or functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
123 lines
4.5 KiB
TypeScript
123 lines
4.5 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { IS_PLATFORM, useParams } from 'common'
|
|
import { parseAsString, useQueryState } from 'nuqs'
|
|
import { useEffect, useMemo } from 'react'
|
|
import { toast } from 'sonner'
|
|
import { Card, Table, TableBody, TableHead, TableHeader, TableRow } from 'ui'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { APIKeyRow } from './APIKeyRow'
|
|
import { CreateSecretAPIKeyDialog } from './CreateSecretAPIKeyDialog'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { FormHeader } from '@/components/ui/Forms/FormHeader'
|
|
import { NoPermission } from '@/components/ui/NoPermission'
|
|
import { useAPIKeyDeleteMutation } from '@/data/api-keys/api-key-delete-mutation'
|
|
import type { APIKeysData } from '@/data/api-keys/api-keys-query'
|
|
import { useAPIKeysQuery } from '@/data/api-keys/api-keys-query'
|
|
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
|
|
|
|
export const SecretAPIKeys = () => {
|
|
const { ref: projectRef } = useParams()
|
|
const { can: canReadAPIKeys, isLoading: isLoadingPermissions } = useAsyncCheckPermissions(
|
|
PermissionAction.SECRETS_READ,
|
|
'*'
|
|
)
|
|
|
|
const {
|
|
data: apiKeysData,
|
|
error,
|
|
isSuccess: isSuccessApiKeys,
|
|
isPending: isLoadingApiKeys,
|
|
isError: isErrorApiKeys,
|
|
} = useAPIKeysQuery({ projectRef, reveal: false }, { enabled: canReadAPIKeys })
|
|
|
|
const secretApiKeys = useMemo(
|
|
() =>
|
|
apiKeysData?.filter(
|
|
(key): key is Extract<APIKeysData[number], { type: 'secret' }> => key.type === 'secret'
|
|
) ?? [],
|
|
[apiKeysData]
|
|
)
|
|
|
|
const empty = secretApiKeys?.length === 0 && !isLoadingApiKeys && !isLoadingPermissions
|
|
|
|
const [deleteId, setDeleteId] = useQueryState('deleteSecretKey', parseAsString)
|
|
const apiKeyToDelete = secretApiKeys?.find((key) => key.id === deleteId)
|
|
|
|
const {
|
|
mutate: deleteAPIKey,
|
|
isPending: isDeletingAPIKey,
|
|
isSuccess: isDeleteSuccess,
|
|
} = useAPIKeyDeleteMutation({
|
|
onSuccess: () => {
|
|
toast.success('Successfully deleted secret key')
|
|
setDeleteId(null)
|
|
},
|
|
})
|
|
|
|
const onDeleteAPIKey = (apiKey: Extract<APIKeysData[number], { type: 'secret' }>) => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
if (!apiKey.id) return console.error('API key ID is required')
|
|
deleteAPIKey({ projectRef, id: apiKey.id })
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (isSuccessApiKeys && !!deleteId && !apiKeyToDelete && !isDeleteSuccess) {
|
|
toast('Unable to find secret key')
|
|
setDeleteId(null)
|
|
}
|
|
}, [apiKeyToDelete, deleteId, isDeleteSuccess, isSuccessApiKeys, setDeleteId])
|
|
|
|
return (
|
|
<div className="pb-30">
|
|
<FormHeader
|
|
title="Secret keys"
|
|
description="These API keys allow privileged access to your project's APIs. Use in servers, functions, workers or other backend components of your application."
|
|
actions={IS_PLATFORM ? <CreateSecretAPIKeyDialog /> : null}
|
|
/>
|
|
|
|
{!canReadAPIKeys && !isLoadingPermissions ? (
|
|
<NoPermission resourceText="view API keys" />
|
|
) : isLoadingApiKeys || isLoadingPermissions ? (
|
|
<GenericSkeletonLoader />
|
|
) : isErrorApiKeys ? (
|
|
<AlertError error={error} subject="Failed to load secret API keys" />
|
|
) : empty ? (
|
|
<Card>
|
|
<div className="rounded-b-md! overflow-hidden py-12 flex flex-col gap-1 items-center justify-center">
|
|
<p className="text-sm text-foreground">No secret API keys found</p>
|
|
<p className="text-sm text-foreground-light">
|
|
Your project is not accessible via secret keys—there are no active secret keys
|
|
created.
|
|
</p>
|
|
</div>
|
|
</Card>
|
|
) : (
|
|
<Card className="bg-surface-100">
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow className="bg-200">
|
|
<TableHead>Name</TableHead>
|
|
<TableHead>API Key</TableHead>
|
|
{IS_PLATFORM && <TableHead />}
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{secretApiKeys.map((apiKey) => (
|
|
<APIKeyRow
|
|
key={apiKey.id}
|
|
apiKey={apiKey}
|
|
isDeleting={apiKeyToDelete?.id === apiKey.id && isDeletingAPIKey}
|
|
onDelete={() => onDeleteAPIKey(apiKey)}
|
|
setKeyToDelete={setDeleteId}
|
|
isDeleteModalOpen={apiKeyToDelete?.id === apiKey.id}
|
|
/>
|
|
))}
|
|
</TableBody>
|
|
</Table>
|
|
</Card>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|