mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem Nothing is tracked on the API keys pages (new and legacy), so we can't tell which keys people copy, how often they create or delete keys, or how quickly projects disable legacy keys. Closes FE-5030. ## Solution Adds five events, defined in `packages/common/telemetry-constants.ts` and fired through `useTrack()`: | Event | When | Properties | | --- | --- | --- | | `api_key_copied` | User copies a publishable, secret, or legacy anon/service_role key with its Copy button. Keyboard copies aren't counted. Not fired when blocked by permissions or when the copy fails. | `keyType` | | `api_key_reveal_clicked` | User reveals a secret or legacy service_role key (not on hide) | `keyType` | | `api_key_created` | Key created from the dialog, or by the first-time setup (fires once per key) | `keyType`, `source` | | `api_key_removed` | Key deleted after confirming in the modal | `keyType` | | `legacy_api_keys_updated` | Legacy keys disabled or re-enabled | `enabled` | - Create, delete, and legacy toggle fire in the mutation hook's `onSuccess`, so failed attempts aren't counted and the event still fires if the component unmounts mid-request. They're attributed to the mutation's own project. Copy and reveal fire in the click handler. - Delete is tracked in `SecretAPIKeys` / `PublishableAPIKeys`, where the confirm modal and mutation live, not in the dropdown item. - No key names or values in properties. - `data-attr` added to the copy, reveal, create, delete, and docs controls (static strings; Studio's PostHog autocapture is currently off, so these send nothing today). `DocsButton` gets an optional `data-attr` prop. - `ui-patterns` `Input` gets optional `onReveal` and `onCopied` callbacks. `onCopied` fires only for the Copy button, so legacy and new keys count copies the same way. - The empty-state sample keys are `inert`, so their buttons don't copy or track. - New `getLegacyApiKeyType` helper maps the legacy `anon` / `service_role` tags to the event's `keyType`. Tests cover copy, reveal, the no-event-on-hide and denied-grant cases, the legacy toggle, and the key-type helper. Success paths for the create dialogs and delete aren't covered. ## How to test - [ ] Open `/project/[ref]/settings/api-keys`, copy a publishable and a secret key, reveal a secret key, and check `api_key_copied` and `api_key_reveal_clicked` in PostHog (staging) with the expected `keyType` - [ ] Create and delete a publishable and a secret key and check `api_key_created` / `api_key_removed` - [ ] On the legacy page, copy anon and service_role, reveal service_role, then disable and re-enable the keys and check `legacy_api_keys_updated`
120 lines
3.7 KiB
TypeScript
120 lines
3.7 KiB
TypeScript
import {
|
|
Card,
|
|
CardContent,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from 'ui'
|
|
|
|
import { ApiKeyPill } from './ApiKeyPill'
|
|
import { CreateNewAPIKeysButton } from './CreateNewAPIKeysButton'
|
|
import { FeatureBanner } from '@/components/ui/FeatureBanner'
|
|
import { APIKeysData } from '@/data/api-keys/api-keys-query'
|
|
|
|
// Mock API Keys for demo
|
|
const mockApiKeys = [
|
|
{
|
|
id: 'mock-id-2',
|
|
type: 'publishable',
|
|
api_key: 'sb_publishable_ltaNA7nnVozoSCOcZIjg',
|
|
name: 'web',
|
|
},
|
|
{
|
|
id: 'mock-id-3',
|
|
type: 'publishable',
|
|
api_key: 'sb_publishable_YpotEpinEWsC2dI7FIKI',
|
|
name: 'mobile',
|
|
},
|
|
{
|
|
id: 'mock-id-1',
|
|
type: 'secret',
|
|
api_key: 'sb_secret_8I4Se•••••••••••••',
|
|
name: 'backend_api',
|
|
},
|
|
] as Extract<APIKeysData[number], { type: 'secret' | 'publishable' }>[]
|
|
|
|
/**
|
|
* Reusable table illustration component
|
|
*/
|
|
const ApiKeysTableIllustration = () => {
|
|
return (
|
|
// inert: the sample keys are decoration, so their Copy and Reveal buttons must not work or track
|
|
<Card inert className="w-full overflow-hidden opacity-60 pointer-events-none bg-surface-100">
|
|
<CardContent className="p-0">
|
|
<Table className="p-5">
|
|
<TableHeader>
|
|
<TableRow className="bg-200">
|
|
<TableHead
|
|
key=""
|
|
className="text-left font-mono uppercase text-xs text-foreground-lighter h-auto py-2 overflow-hidden w-[180px]"
|
|
>
|
|
Name
|
|
</TableHead>
|
|
<TableHead className="text-left font-mono uppercase text-xs text-foreground-lighter h-auto py-2 pr-0">
|
|
API Key
|
|
</TableHead>
|
|
<TableHead
|
|
className="text-right font-mono uppercase text-xs text-foreground-lighter h-auto py-2"
|
|
key="actions"
|
|
/>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{mockApiKeys.map((apiKey) => (
|
|
<TableRow key={apiKey.id}>
|
|
<TableCell className="py-2 w-[180px]">{apiKey.name}</TableCell>
|
|
<TableCell className="py-2">
|
|
<div className="flex flex-row gap-2">
|
|
<ApiKeyPill apiKey={apiKey} />
|
|
</div>
|
|
</TableCell>
|
|
<TableCell />
|
|
</TableRow>
|
|
))}
|
|
</TableBody>
|
|
</Table>
|
|
</CardContent>
|
|
</Card>
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Reusable illustration with gradient overlay component
|
|
*/
|
|
const ApiKeysIllustrationWithOverlay = () => {
|
|
return (
|
|
<>
|
|
{/* Gradient overlay - horizontal on desktop, vertical on mobile */}
|
|
<div
|
|
className="absolute inset-x-0 bottom-0 h-1/2 xl:h-full xl:inset-x-auto xl:-right-16 xl:top-3 w-full xl:w-2/3
|
|
bg-linear-to-t xl:bg-linear-to-l
|
|
from-background-alternative via-background-alternative/90 via-5% to-transparent
|
|
z-3 pointer-events-none xl:max-w-[500px]"
|
|
/>
|
|
|
|
<div className="absolute scale-100 left-10 -bottom-14 w-[720px] xl:w-[500px] xl:left-auto xl:right-[-200px] 2xl:-right-16 xl:top-[21px] xl:scale-75">
|
|
<ApiKeysTableIllustration />
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export const ApiKeysCreateCallout = () => {
|
|
return (
|
|
<FeatureBanner illustration={<ApiKeysIllustrationWithOverlay />} bgAlt>
|
|
<div className="flex flex-col gap-0 z-2">
|
|
<p className="text-sm text-foreground">Create API keys</p>
|
|
<p className="text-sm text-foreground-lighter lg:max-w-sm 2xl:max-w-none">
|
|
Use keys to authenticate requests to your app
|
|
</p>
|
|
<div className="mt-4">
|
|
<CreateNewAPIKeysButton />
|
|
</div>
|
|
</div>
|
|
</FeatureBanner>
|
|
)
|
|
}
|