Files
Charis 395a54f2b7 feat(studio): gate jwt signing keys, legacy api keys, and third-party auth on grants (#53241)
Resolves
[FE-4732](https://linear.app/supabase/issue/FE-4732/grants-rollout-jwt-signing-keys-legacy-api-keys-and-third-party-auth).

## Changes
Gates the JWT signing keys, legacy API keys, and third-party auth
endpoints on grants instead of `unguarded.migrating`, and replaces their
V2 permission guards with `useGrant`:
- **Data layer (11 sites):** `data/jwt-signing-keys/*`,
`data/api-keys/legacy-api-keys-status-query`,
`data/api-keys/legacy-api-key-toggle-mutation`, and
`data/third-party-auth/*`. Queries become grant-gated query option
factories; mutations take the grant in their variables.
- **Consumers:** the JWT settings page, the JWT signing keys table and
its dialogs, `jwt-settings`, `ToggleLegacyApiKeys`, `Project/APIKeys`,
and the third-party auth page, form, and create dialogs. Each consumer
renders denied and error states.
- **JWT signing keys table:**
- It's gated only on the signing keys reads (`GET signing-keys` and `GET
signing-keys/legacy`, both `auth_signing_keys_read`).
- The legacy API keys status is only used by the revoke dialogs. If it
can't be read, revoking the legacy JWT secret fails closed: the user
sees the "disable legacy API keys first" warning, with copy explaining
why, instead of the confirm modal.
- **Legacy JWT secret query:** a 404 (secret not imported as a signing
key yet) resolves to `null` and shows the "Migrate JWT secret" panel.
Other errors now render an error instead of being treated as "not
migrated".
- **Write actions:**
- `getWriteGrantTooltip` moves from `APIKeys.utils` to `lib/grants` and
takes a resource noun. Disabled write actions use it to explain why
they're disabled.
- New `getWriteGrantToastMessage`: handlers that run without a grant now
show a toast instead of silently doing nothing. This includes the API
keys handlers from #52966.

## Permission changes
- **Legacy API keys toggle and status** (`GET`/`PUT
/v1/projects/{ref}/api-keys/legacy`): the guard moves from
`auth_signing_keys_read`/`_write` to the endpoint annotation,
`api_gateway_keys_read`/`_write`. The annotation was confirmed against
the backend controller (FE-4728). As a result, the JWT signing keys
table's legacy revoke check now depends on `api_gateway_keys_read`.
- **API keys last-used analytics**
(`/platform/projects/{ref}/analytics/endpoints/api_keys.last_used.otel`):
this endpoint uses legacy permissions (`analytics:Read` on `logflare`),
not FGA. Its check moves from the V2 `auth_signing_keys_read` check to
`useAsyncCheckPermissions(PermissionAction.ANALYTICS_READ, 'logflare')`.
- Every other guard already matched its annotation:
  - `auth_signing_keys_read`/`_write` for signing keys
  - `auth_config_read`/`_write` for third-party auth

## Testing
- Data layer: `jwt-signing-keys.test.ts`, `legacy-api-keys.test.ts`, and
`third-party-auth.test.ts` cover every migrated fetcher, check that
factories stay disabled without a grant, and cover legacy-key 404 vs.
500.
- `jwt-secret-keys-table/index.platform.test.tsx`:
- Legacy status denied: the table still renders, and revoking the legacy
key shows only the warning.
  - Legacy status known enabled or disabled.
  - Signing keys read denied.
  - Legacy key 404 vs. 500.
- `create-key-dialog.platform.test.tsx`: triggering create without a
grant shows the toast and sends no request.
- `ToggleLegacyApiKeys.platform.test.tsx`,
`ThirdPartyAuthForm.platform.test.tsx`, and
`settings/jwt/index.platform.test.tsx`: granted, denied, error, and
partial-permission cases.
- `lib/grants.test.ts`: the tooltip and toast helpers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-11-10 15:30:58 -05:00

633 lines
25 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useQuery } from '@tanstack/react-query'
import { IS_PLATFORM, useFlag, useParams } from 'common'
import { AlertCircleIcon, RotateCwIcon, TimerIcon } from 'lucide-react'
import { AnimatePresence } from 'motion/react'
import { useMemo, useRef, useState } from 'react'
import { toast } from 'sonner'
import {
AlertDialog,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
Card,
CardContent,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogSection,
DialogSectionSeparator,
DialogTitle,
Table,
TableBody,
TableHead,
TableHeader,
TableRow,
} from 'ui'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import { StartUsingJwtSigningKeysBanner } from '../start-using-keys-banner'
import { ActionPanel } from './action-panel'
import { CreateKeyDialog } from './create-key-dialog'
import { KeyDetailsDialog } from './key-details-dialog'
import { RotateKeyDialog } from './rotate-key-dialog'
import { SigningKeyRow } from './signing-key-row'
import { AlertError } from '@/components/ui/AlertError'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { TextConfirmModal } from '@/components/ui/TextConfirmModalWrapper'
import {
getJWTSigningKeyLastUsedAt,
useApiKeysLastUsedQuery,
} from '@/data/analytics/api-keys-last-used-query'
import { legacyAPIKeysStatusQueryOptions } from '@/data/api-keys/legacy-api-keys-status-query'
import { useJWTSigningKeyDeleteMutation } from '@/data/jwt-signing-keys/jwt-signing-key-delete-mutation'
import { useJWTSigningKeyUpdateMutation } from '@/data/jwt-signing-keys/jwt-signing-key-update-mutation'
import {
JWTSigningKey,
jwtSigningKeysQueryOptions,
} from '@/data/jwt-signing-keys/jwt-signing-keys-query'
import { useLegacyJWTSigningKeyCreateMutation } from '@/data/jwt-signing-keys/legacy-jwt-signing-key-create-mutation'
import { legacyJWTSigningKeyQueryOptions } from '@/data/jwt-signing-keys/legacy-jwt-signing-key-query'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { getWriteGrantToastMessage, getWriteGrantTooltip, useGrant } from '@/lib/grants'
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
type DialogType = 'legacy' | 'create' | 'rotate' | 'key-details' | 'revoke' | 'delete'
type LegacyRevokeBlockedReason = 'denied' | 'error' | 'enabled'
const LEGACY_REVOKE_BLOCKED_DESCRIPTION = {
denied:
"You can't revoke the legacy JWT secret until JWT-based legacy API keys are disabled. You don't have permission to check or change that setting.",
error:
"You can't revoke the legacy JWT secret until JWT-based legacy API keys are disabled, and we couldn't check their status. Try again later.",
enabled:
"It's not possible to revoke the legacy JWT secret unless you have already disabled JWT-based legacy API keys. This is because revoking the JWT secret invalidates the JWT-based legacy API keys.",
} satisfies Record<LegacyRevokeBlockedReason, string>
const JWTSecretKeysTableHeader = ({
showLastRotatedAt = false,
}: {
showLastRotatedAt?: boolean
}) => {
const showApiKeysLastUsed = useFlag('showApiKeysLastUsed')
return (
<TableHeader>
<TableRow>
<TableHead className="w-[315px]">Key</TableHead>
<TableHead className="w-[200px]">Type</TableHead>
<TableHead className="text-right w-[160px] hidden xl:table-cell">Created at</TableHead>
{IS_PLATFORM && showApiKeysLastUsed && (
<TableHead className="text-right w-[160px]">Last used</TableHead>
)}
{showLastRotatedAt && (
<TableHead className="text-right hidden xl:table-cell">Last rotated at</TableHead>
)}
<TableHead />
</TableRow>
</TableHeader>
)
}
export const JWTSecretKeysTable = () => {
const { ref: projectRef } = useParams()
const { data: project, isPending: isProjectLoading } = useSelectedProjectQuery()
const [selectedKey, setSelectedKey] = useState<JWTSigningKey>()
const [selectedKeyToUpdate, setSelectedKeyToUpdate] = useState<string>()
const [shownDialog, setShownDialog] = useState<DialogType>()
const showApiKeysLastUsed = useFlag('showApiKeysLastUsed')
const signingKeysGrant = useGrant('GET /v1/projects/{ref}/config/auth/signing-keys', {
projectRef,
})
const legacyKeyGrant = useGrant('GET /v1/projects/{ref}/config/auth/signing-keys/legacy', {
projectRef,
})
const legacyStatusGrant = useGrant('GET /v1/projects/{ref}/api-keys/legacy', { projectRef })
const migrateGrant = useGrant('POST /v1/projects/{ref}/config/auth/signing-keys/legacy', {
projectRef,
})
const updateGrant = useGrant('PATCH /v1/projects/{ref}/config/auth/signing-keys/{id}', {
projectRef,
})
const deleteGrant = useGrant('DELETE /v1/projects/{ref}/config/auth/signing-keys/{id}', {
projectRef,
})
// The last-used analytics endpoint still uses legacy permissions (analytics:Read on logflare), not FGA
const { can: canReadLastUsed } = useAsyncCheckPermissions(
PermissionAction.ANALYTICS_READ,
'logflare'
)
const now = useRef(new Date()).current
const {
data: lastUsedData,
isError: isLastUsedError,
isLoading: isLoadingLastUsed,
} = useApiKeysLastUsedQuery(
{
projectRef,
isoTimestampStart: new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString(),
isoTimestampEnd: now.toISOString(),
},
{ enabled: canReadLastUsed && showApiKeysLastUsed }
)
const {
data: signingKeys,
error: signingKeysError,
isPending: isLoadingSigningKeys,
isError: isSigningKeysError,
} = useQuery(jwtSigningKeysQueryOptions({ projectRef, grant: signingKeysGrant.grant }))
// A 404 means the legacy JWT secret hasn't been migrated yet (`legacyKey` is `null`); other
// errors are real failures.
const {
data: legacyKey,
error: legacyKeyError,
isPending: isLoadingLegacyKey,
isError: isLegacyKeyError,
} = useQuery(legacyJWTSigningKeyQueryOptions({ projectRef, grant: legacyKeyGrant.grant }))
// Only the legacy revoke dialogs use this status, so it never gates the table. It stays unknown
// when its grant is denied or the request fails, and the dialogs fail closed in that case.
const { data: legacyAPIKeysStatus, isError: isLegacyAPIKeysStatusError } = useQuery(
legacyAPIKeysStatusQueryOptions({ projectRef, grant: legacyStatusGrant.grant })
)
// The legacy key is needed too: without it the table would show the "Migrate JWT secret" panel
const readGrants = [signingKeysGrant, legacyKeyGrant]
const isReadDenied = readGrants.some((grant) => grant.status === 'denied')
const isReadGrantLoading = readGrants.some((grant) => grant.status === 'loading')
const readGrantError = readGrants.find((grant) => grant.status === 'error')
const { mutate: migrateJWTSecret, isPending: isMigrating } = useLegacyJWTSigningKeyCreateMutation(
{
onSuccess: () => {
setShownDialog(undefined)
toast.success('Successfully migrated JWT secret!')
},
}
)
const { mutate: updateJWTSigningKey, isPending: isUpdatingJWTSigningKey } =
useJWTSigningKeyUpdateMutation({
onSuccess: () => {
resetDialog()
setSelectedKeyToUpdate(undefined)
},
})
const { mutate: deleteJWTSigningKey, isPending: isDeletingJWTSigningKey } =
useJWTSigningKeyDeleteMutation({
onSuccess: () => resetDialog(),
onError: (error) => {
resetDialog()
toast.error(`Failed to delete JWT signing key: ${error.message}`)
},
})
const isPendingMutation = isUpdatingJWTSigningKey || isDeletingJWTSigningKey || isMigrating
const isLoading =
isProjectLoading || isReadGrantLoading || isLoadingSigningKeys || isLoadingLegacyKey
const isLegacyAPIKeysKnownDisabled = legacyAPIKeysStatus?.enabled === false
const isLegacyAPIKeysStatusUnknown = legacyAPIKeysStatus === undefined
const isRevokingLegacyKey = legacyKey?.id !== undefined && legacyKey.id === selectedKey?.id
const canConfirmRevoke = !isRevokingLegacyKey || isLegacyAPIKeysKnownDisabled
const legacyRevokeBlockedReason: LegacyRevokeBlockedReason =
isLegacyAPIKeysStatusUnknown && legacyStatusGrant.status === 'denied'
? 'denied'
: isLegacyAPIKeysStatusUnknown && isLegacyAPIKeysStatusError
? 'error'
: 'enabled'
const sortedKeys = useMemo(() => {
if (!signingKeys || !Array.isArray(signingKeys.keys)) return []
return signingKeys.keys.sort((a: JWTSigningKey, b: JWTSigningKey) => {
const order: Record<JWTSigningKey['status'], number> = {
standby: 0,
in_use: 1,
previously_used: 2,
revoked: 3,
}
return (
order[a.status] - order[b.status] ||
new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
)
})
}, [signingKeys])
const standbyKey = useMemo(() => sortedKeys.find((key) => key.status === 'standby'), [sortedKeys])
const inUseKey = useMemo(() => sortedKeys.find((key) => key.status === 'in_use'), [sortedKeys])
const previouslyUsedKeys = useMemo(
() => sortedKeys.filter((key) => key.status === 'previously_used'),
[sortedKeys]
)
const revokedKeys = useMemo(
() => sortedKeys.filter((key) => key.status === 'revoked'),
[sortedKeys]
)
const getLastUsedAt = (keyId: string) => getJWTSigningKeyLastUsedAt(lastUsedData ?? [], keyId)
const resetDialog = () => {
setSelectedKey(undefined)
setShownDialog(undefined)
}
const handlePreviouslyUsedKey = async (keyId: string) => {
if (!updateGrant.grant) {
toast.error(getWriteGrantToastMessage(updateGrant.status, 'update', 'signing keys'))
return
}
setSelectedKeyToUpdate(keyId)
updateJWTSigningKey(
{ projectRef, grant: updateGrant.grant, keyId, status: 'previously_used' },
{ onSuccess: () => toast.success('Successfully moved key to previously used') }
)
}
const handleStandbyKey = (keyId: string) => {
if (!updateGrant.grant) {
toast.error(getWriteGrantToastMessage(updateGrant.status, 'update', 'signing keys'))
return
}
setSelectedKeyToUpdate(keyId)
updateJWTSigningKey(
{ projectRef: projectRef!, grant: updateGrant.grant, keyId, status: 'standby' },
{ onSuccess: () => toast.success('Successfully moved key to standby') }
)
}
const handleRevokeKey = (keyId: string) => {
if (!updateGrant.grant) {
toast.error(getWriteGrantToastMessage(updateGrant.status, 'revoke', 'signing keys'))
return
}
updateJWTSigningKey(
{ projectRef: projectRef!, grant: updateGrant.grant, keyId, status: 'revoked' },
{ onSuccess: () => toast.success('Successfully revoked key') }
)
}
const handleDeleteKey = (keyId: string) => {
if (!deleteGrant.grant) {
toast.error(getWriteGrantToastMessage(deleteGrant.status, 'delete', 'signing keys'))
return
}
deleteJWTSigningKey(
{ projectRef: projectRef!, grant: deleteGrant.grant, keyId },
{ onSuccess: () => toast.success('Successfully deleted key') }
)
}
if (readGrantError?.status === 'error') {
return (
<AlertError
error={readGrantError.error}
subject="Failed to check JWT signing keys permissions"
/>
)
}
if (isReadDenied) {
return (
<div className="bg-surface-100 rounded-md border shadow-xs">
<div className="flex items-center py-8 px-8 space-x-2">
<AlertCircleIcon size={16} strokeWidth={1.5} />
<p className="text-sm text-foreground-light">
You don't have permission to view JWT signing keys. These keys are restricted to users
with higher access levels.
</p>
</div>
</div>
)
}
if (isLoading) {
return <GenericSkeletonLoader />
}
if (isSigningKeysError) {
return <AlertError error={signingKeysError} subject="Failed to retrieve JWT signing keys" />
}
if (isLegacyKeyError) {
return (
<AlertError error={legacyKeyError} subject="Failed to retrieve legacy JWT secret status" />
)
}
return (
<>
<div className="-space-y-px">
{legacyKey ? (
<>
{standbyKey ? (
<ActionPanel
title="Rotate Signing Key"
description="Switch the standby key to in use. All new JSON Web Tokens issued by Supabase Auth will be signed with this key."
buttonLabel="Rotate keys"
onClick={() => setShownDialog('rotate')}
loading={isUpdatingJWTSigningKey}
icon={<RotateCwIcon className="size-4" />}
variant="primary"
/>
) : (
<ActionPanel
title="Create standby key"
description="Set up a new key which you can switch to once it has been picked up by all components of your application."
buttonLabel="Create Standby Key"
onClick={() => setShownDialog('create')}
loading={isPendingMutation}
variant="primary"
shortcutId={SHORTCUT_IDS.JWT_KEYS_CREATE_STANDBY}
/>
)}
</>
) : (
<StartUsingJwtSigningKeysBanner
onClick={() => setShownDialog('legacy')}
isLoading={isMigrating}
/>
)}
</div>
{sortedKeys.length > 0 && (
<>
<Card>
<CardContent className="p-0">
<Table>
<JWTSecretKeysTableHeader />
<TableBody>
<AnimatePresence>
{inUseKey && (
<SigningKeyRow
key={inUseKey.id}
signingKey={inUseKey}
setSelectedKey={setSelectedKey}
setShownDialog={setShownDialog}
handleStandbyKey={handleStandbyKey}
updateGrantStatus={updateGrant.status}
deleteGrantStatus={deleteGrant.status}
handlePreviouslyUsedKey={handlePreviouslyUsedKey}
legacyKey={legacyKey}
standbyKey={standbyKey}
lastUsedAt={getLastUsedAt(inUseKey.id)}
isLoadingLastUsed={isLoadingLastUsed}
isLastUsedError={isLastUsedError}
isLastUsedVisible={IS_PLATFORM && showApiKeysLastUsed}
/>
)}
{standbyKey && (
<SigningKeyRow
key={standbyKey.id}
signingKey={standbyKey}
legacyKey={legacyKey}
standbyKey={standbyKey}
isLoading={selectedKeyToUpdate === standbyKey.id && isUpdatingJWTSigningKey}
setSelectedKey={setSelectedKey}
setShownDialog={setShownDialog}
handleStandbyKey={handleStandbyKey}
updateGrantStatus={updateGrant.status}
deleteGrantStatus={deleteGrant.status}
handlePreviouslyUsedKey={handlePreviouslyUsedKey}
lastUsedAt={getLastUsedAt(standbyKey.id)}
isLoadingLastUsed={isLoadingLastUsed}
isLastUsedError={isLastUsedError}
isLastUsedVisible={IS_PLATFORM && showApiKeysLastUsed}
/>
)}
</AnimatePresence>
</TableBody>
</Table>
</CardContent>
</Card>
<div className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
<h2>Previously used keys</h2>
<p className="text-sm text-foreground-lighter">
These JWT signing keys are still used to{' '}
<em className="text-foreground not-italic">verify tokens</em> that are yet to
expire. Revoke once all tokens have expired.
</p>
</div>
<Card className="overflow-hidden">
<CardContent className="p-0">
{previouslyUsedKeys.length > 0 ? (
<Table>
<JWTSecretKeysTableHeader showLastRotatedAt />
<TableBody>
<AnimatePresence>
{previouslyUsedKeys.map((key) => (
<SigningKeyRow
key={key.id}
signingKey={key}
legacyKey={legacyKey}
standbyKey={standbyKey}
isLoading={selectedKeyToUpdate === key.id && isUpdatingJWTSigningKey}
setSelectedKey={setSelectedKey}
setShownDialog={setShownDialog}
handleStandbyKey={handleStandbyKey}
updateGrantStatus={updateGrant.status}
deleteGrantStatus={deleteGrant.status}
handlePreviouslyUsedKey={handlePreviouslyUsedKey}
lastUsedAt={getLastUsedAt(key.id)}
isLoadingLastUsed={isLoadingLastUsed}
isLastUsedError={isLastUsedError}
isLastUsedVisible={IS_PLATFORM && showApiKeysLastUsed}
/>
))}
</AnimatePresence>
</TableBody>
</Table>
) : (
<div className="flex flex-col items-center justify-center text-center text-foreground-light p-8 gap-2">
<TimerIcon className="size-6 text-foreground-lighter" />
<div className="flex flex-col gap-1">
<p className="text-sm font-medium">No previously used keys</p>
<p className="text-xs text-foreground-lighter">
Rotated keys will appear here for verification of existing tokens
</p>
</div>
</div>
)}
</CardContent>
</Card>
</div>
</>
)}
{revokedKeys.length > 0 && (
<div className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
<h2>Revoked keys</h2>
<p className="text-sm text-foreground-lighter">
These keys are no longer used to verify or sign JWTs.
</p>
</div>
<Card className="overflow-hidden">
<CardContent className="p-0">
<Table>
<JWTSecretKeysTableHeader showLastRotatedAt />
<TableBody>
<AnimatePresence>
{revokedKeys.map((key) => (
<SigningKeyRow
key={key.id}
signingKey={key}
setSelectedKey={setSelectedKey}
setShownDialog={setShownDialog}
handleStandbyKey={handleStandbyKey}
updateGrantStatus={updateGrant.status}
deleteGrantStatus={deleteGrant.status}
handlePreviouslyUsedKey={handlePreviouslyUsedKey}
legacyKey={legacyKey}
standbyKey={standbyKey}
lastUsedAt={getLastUsedAt(key.id)}
isLoadingLastUsed={isLoadingLastUsed}
isLastUsedError={isLastUsedError}
isLastUsedVisible={IS_PLATFORM && showApiKeysLastUsed}
/>
))}
</AnimatePresence>
</TableBody>
</Table>
</CardContent>
</Card>
</div>
)}
<Dialog open={shownDialog === 'legacy'} onOpenChange={resetDialog}>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>Start using new JWT signing keys</DialogTitle>
</DialogHeader>
<DialogSectionSeparator />
<DialogSection className="flex flex-col gap-2 text-sm text-foreground-light">
<p>
Your project today uses a legacy symmetric JWT secret to create JWTs. To be able to
use an asymmetric JWT signing key you first have to migrate it to the new approach.
</p>
<p>This change does not cause any downtime on your project.</p>
</DialogSection>
<DialogFooter>
<ButtonTooltip
variant="primary"
loading={isMigrating}
disabled={!migrateGrant.grant}
tooltip={{
content: {
side: 'top',
text: getWriteGrantTooltip(migrateGrant.status, 'migrate', 'the JWT secret'),
},
}}
onClick={() => {
if (!migrateGrant.grant) {
toast.error(
getWriteGrantToastMessage(migrateGrant.status, 'migrate', 'the JWT secret')
)
return
}
migrateJWTSecret({ projectRef: projectRef!, grant: migrateGrant.grant })
}}
>
Migrate JWT secret
</ButtonTooltip>
</DialogFooter>
</DialogContent>
</Dialog>
<Dialog open={shownDialog === 'create'} onOpenChange={resetDialog}>
<DialogContent className="sm:max-w-[425px]">
<CreateKeyDialog projectRef={projectRef!} onClose={resetDialog} />
</DialogContent>
</Dialog>
{standbyKey && inUseKey && projectRef && (
<Dialog open={shownDialog === 'rotate'} onOpenChange={resetDialog}>
<DialogContent className="sm:max-w-[425px]">
<RotateKeyDialog
projectRef={projectRef}
standbyKey={standbyKey}
inUseKey={inUseKey}
onClose={resetDialog}
/>
</DialogContent>
</Dialog>
)}
{selectedKey && project && (
<Dialog open={shownDialog === 'key-details'} onOpenChange={resetDialog}>
<DialogContent className="sm:max-w-lg">
<KeyDetailsDialog
selectedKey={selectedKey}
restURL={project.restUrl}
onClose={resetDialog}
/>
</DialogContent>
</Dialog>
)}
{selectedKey && selectedKey.status === 'previously_used' && canConfirmRevoke && (
<TextConfirmModal
visible={shownDialog === 'revoke'}
loading={isPendingMutation}
onConfirm={() => handleRevokeKey(selectedKey.id)}
onCancel={resetDialog}
title={`Revoke ${selectedKey.id}`}
confirmString={selectedKey.id}
confirmLabel="Yes, revoke this signing key"
confirmPlaceholder="Type the ID of the key to confirm"
variant="destructive"
alert={{
title: 'This key will no longer be trusted!',
description:
'By revoking a signing key, all applications trusting it will no longer do so. If there are JWTs (access tokens) that are valid at the time of revocation, they will no longer be trusted, causing users with such JWTs to be signed out.',
}}
/>
)}
{selectedKey && selectedKey.status === 'previously_used' && !canConfirmRevoke && (
<AlertDialog open={shownDialog === 'revoke'} onOpenChange={() => resetDialog()}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Disable JWT-based legacy API keys first</AlertDialogTitle>
</AlertDialogHeader>
<AlertDialogDescription>
{LEGACY_REVOKE_BLOCKED_DESCRIPTION[legacyRevokeBlockedReason]}
</AlertDialogDescription>
<AlertDialogFooter>
<AlertDialogCancel>OK</AlertDialogCancel>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)}
{selectedKey && selectedKey.status === 'revoked' && (
<TextConfirmModal
visible={shownDialog === 'delete'}
loading={isPendingMutation}
onConfirm={() => handleDeleteKey(selectedKey.id)}
onCancel={resetDialog}
title={`Permanently delete ${selectedKey.id}`}
confirmString={selectedKey.id}
confirmLabel="Yes, permanently delete this key"
confirmPlaceholder="Type the ID of the key to confirm"
variant="destructive"
alert={{
title: 'This key will be permanently deleted.',
description:
'The private key and all information about this key will be permanently deleted from our records. This action cannot be undone.',
}}
/>
)}
</>
)
}