Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Clean up JWT keys page (#51745)

Joshen Limad370748693b
diff --git a/apps/studio/components/interfaces/JwtSecrets/algorithm-hover-card.tsx b/apps/studio/components/interfaces/JwtSecrets/algorithm-hover-card.tsx
index 2b056ee735f..816b75fd860 100644
--- a/apps/studio/components/interfaces/JwtSecrets/algorithm-hover-card.tsx
+++ b/apps/studio/components/interfaces/JwtSecrets/algorithm-hover-card.tsx
@@ -1,29 +1,19 @@
-import {
- ExternalLinkIcon,
- HelpCircleIcon,
- LockKeyholeOpenIcon,
- RectangleEllipsisIcon,
-} from 'lucide-react'
+import { ExternalLinkIcon, HelpCircleIcon } from 'lucide-react'
import { HoverCard, HoverCardContent, HoverCardTrigger } from 'ui'
import { AlgorithmDetail, algorithmDetails } from './algorithm-details'
interface AlgorithmHoverCardProps {
algorithm: keyof typeof algorithmDetails
- legacy?: boolean
}
-export const AlgorithmHoverCard = ({ algorithm, legacy }: AlgorithmHoverCardProps) => {
+export const AlgorithmHoverCard = ({ algorithm }: AlgorithmHoverCardProps) => {
const details: AlgorithmDetail = algorithmDetails[algorithm]
return (
- <div className="flex items-center gap-x-2">
- {algorithm === 'HS256' ? (
- <RectangleEllipsisIcon className="shrink-0" size={14} />
- ) : (
- <LockKeyholeOpenIcon className="shrink-0" size={14} />
- )}
- <p>{legacy ? `Legacy ${details.label}` : details.label}</p>
+ <div className="flex items-center gap-x-2 whitespace-nowrap">
+ <p>{details.label}</p>
+
<HoverCard closeDelay={50} openDelay={300}>
<HoverCardTrigger className="min-w-0">
<HelpCircleIcon size={14} className="text-foreground-lighter" />
diff --git a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/action-panel.tsx b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/action-panel.tsx
index 4c7a002ab54..bac6191c851 100644
--- a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/action-panel.tsx
+++ b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/action-panel.tsx
@@ -37,7 +37,7 @@ export const ActionPanel = forwardRef<HTMLDivElement, ActionPanelProps>(
<CardTitle className="text-sm">{title}</CardTitle>
<CardDescription className="max-w-xl">{description}</CardDescription>
</div>
- <div className="flex lg:justify-end flex-">
+ <div className="flex lg:justify-end ">
{shortcutId ? (
<Shortcut
id={shortcutId}
diff --git a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/index.tsx b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/index.tsx
index e05ebb729c8..88eaa62f321 100644
--- a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/index.tsx
+++ b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/index.tsx
@@ -56,6 +56,31 @@ import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
type DialogType = 'legacy' | 'create' | 'rotate' | 'key-details' | 'revoke' | 'delete'
+const JWTSecretKeysTableHeader = ({
+ showLastRotatedAt = false,
+}: {
+ showLastRotatedAt?: boolean
+}) => {
+ const showApiKeysLastUsed = useFlag('showApiKeysLastUsed')
+
+ return (
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-[80px]">Status</TableHead>
+ <TableHead className="w-[315px]">Key ID</TableHead>
+ <TableHead className="w-[200px]">Type</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()
@@ -83,15 +108,11 @@ export const JWTSecretKeysTable = () => {
{ enabled: canReadAPIKeys && showApiKeysLastUsed }
)
const { data: signingKeys, isPending: isLoadingSigningKeys } = useJWTSigningKeysQuery(
- {
- projectRef,
- },
+ { projectRef },
{ enabled: canReadAPIKeys }
)
const { data: legacyKey, isPending: isLoadingLegacyKey } = useLegacyJWTSigningKeyQuery(
- {
- projectRef,
- },
+ { projectRef },
{ enabled: canReadAPIKeys }
)
const { data: legacyAPIKeysStatus, isPending: isLoadingLegacyAPIKeysStatus } =
@@ -225,7 +246,6 @@ export const JWTSecretKeysTable = () => {
onClick={() => setShownDialog('create')}
loading={isPendingMutation}
variant="primary"
- icon={<TimerIcon className="size-4" />}
shortcutId={SHORTCUT_IDS.JWT_KEYS_CREATE_STANDBY}
/>
)}
@@ -240,110 +260,65 @@ export const JWTSecretKeysTable = () => {
{sortedKeys.length > 0 && (
<>
- <div>
- <Card className="w-full overflow-hidden bg-surface-100 border rounded-md">
- <CardContent className="p-0">
- <Table className="p-5">
- <TableHeader className="bg-200">
- <TableRow>
- <TableHead className="text-left font-mono uppercase text-xs text-foreground-muted h-auto py-2 pr-0 w-20">
- Status
- </TableHead>
- <TableHead className="text-left font-mono uppercase text-xs text-foreground-muted h-auto py-2 pl-0">
- Key ID
- </TableHead>
- <TableHead className="text-left font-mono uppercase text-xs text-foreground-muted h-auto py-2">
- Type
- </TableHead>
- <TableHead className="text-right font-mono uppercase text-xs text-foreground-muted h-auto py-2">
- {IS_PLATFORM && showApiKeysLastUsed && 'Last used'}
- </TableHead>
- <TableHead className="text-right font-mono uppercase text-xs text-foreground-muted h-auto py-2">
- Actions
- </TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- <AnimatePresence>
- {standbyKey && (
- <SigningKeyRow
- key={standbyKey.id}
- signingKey={standbyKey}
- legacyKey={legacyKey}
- standbyKey={standbyKey}
- isLoading={
- selectedKeyToUpdate === standbyKey.id && isUpdatingJWTSigningKey
- }
- setSelectedKey={setSelectedKey}
- setShownDialog={setShownDialog}
- handleStandbyKey={handleStandbyKey}
- handlePreviouslyUsedKey={handlePreviouslyUsedKey}
- lastUsedAt={getLastUsedAt(standbyKey.id)}
- isLoadingLastUsed={isLoadingLastUsed}
- isLastUsedError={isLastUsedError}
- isLastUsedVisible={IS_PLATFORM && showApiKeysLastUsed}
- />
- )}
- {inUseKey && (
- <SigningKeyRow
- key={inUseKey.id}
- signingKey={inUseKey}
- setSelectedKey={setSelectedKey}
- setShownDialog={setShownDialog}
- handleStandbyKey={handleStandbyKey}
- handlePreviouslyUsedKey={handlePreviouslyUsedKey}
- legacyKey={legacyKey}
- standbyKey={standbyKey}
- lastUsedAt={getLastUsedAt(inUseKey.id)}
- isLoadingLastUsed={isLoadingLastUsed}
- isLastUsedError={isLastUsedError}
- isLastUsedVisible={IS_PLATFORM && showApiKeysLastUsed}
- />
- )}
- </AnimatePresence>
- </TableBody>
- </Table>
- </CardContent>
- </Card>
- </div>
+ <Card>
+ <CardContent className="p-0">
+ <Table>
+ <JWTSecretKeysTableHeader />
+ <TableBody>
+ <AnimatePresence>
+ {inUseKey && (
+ <SigningKeyRow
+ key={inUseKey.id}
+ signingKey={inUseKey}
+ setSelectedKey={setSelectedKey}
+ setShownDialog={setShownDialog}
+ handleStandbyKey={handleStandbyKey}
+ 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}
+ 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-primary not-italic">verify tokens</em> that are yet to expire.
- Revoke once all tokens have expired.
+ <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 className="p-5">
- <TableHeader className="bg-200">
- <TableRow>
- <TableHead className="text-left font-mono uppercase text-xs text-foreground-muted h-auto py-2 pr-0 w-20">
- Status
- </TableHead>
- <TableHead className="text-left font-mono uppercase text-xs text-foreground-muted h-auto py-2 pl-0">
- Key ID
- </TableHead>
- <TableHead className="text-left font-mono uppercase text-xs text-foreground-muted h-auto py-2">
- Type
- </TableHead>
- {IS_PLATFORM && showApiKeysLastUsed && (
- <TableHead className="text-right font-mono uppercase text-xs text-foreground-muted h-auto py-2">
- Last used
- </TableHead>
- )}
- <TableHead className="text-right font-mono uppercase text-xs text-foreground-muted h-auto py-2 hidden lg:table-cell">
- Last rotated at
- </TableHead>
- <TableHead className="text-right font-mono uppercase text-xs text-foreground-muted h-auto py-2">
- Actions
- </TableHead>
- </TableRow>
- </TableHeader>
+ <Table>
+ <JWTSecretKeysTableHeader showLastRotatedAt />
<TableBody>
<AnimatePresence>
{previouslyUsedKeys.map((key) => (
@@ -393,31 +368,8 @@ export const JWTSecretKeysTable = () => {
</div>
<Card className="overflow-hidden">
<CardContent className="p-0">
- <Table className="p-5">
- <TableHeader className="bg-200">
- <TableRow>
- <TableHead className="text-left font-mono uppercase text-xs text-foreground-muted h-auto py-2 pr-0 w-20">
- Status
- </TableHead>
- <TableHead className="text-left font-mono uppercase text-xs text-foreground-muted h-auto py-2 pl-0">
- Key ID
- </TableHead>
- <TableHead className="text-left font-mono uppercase text-xs text-foreground-muted h-auto py-2">
- Type
- </TableHead>
- {IS_PLATFORM && showApiKeysLastUsed && (
- <TableHead className="text-right font-mono uppercase text-xs text-foreground-muted h-auto py-2">
- Last used
- </TableHead>
- )}
- <TableHead className="text-right font-mono uppercase text-xs text-foreground-muted h-auto py-2 hidden lg:table-cell">
- Last rotated at
- </TableHead>
- <TableHead className="text-right font-mono uppercase text-xs text-foreground-muted h-auto py-2">
- Actions
- </TableHead>
- </TableRow>
- </TableHeader>
+ <Table>
+ <JWTSecretKeysTableHeader showLastRotatedAt />
<TableBody>
<AnimatePresence>
{revokedKeys.map((key) => (
diff --git a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/signing-key-row.tsx b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/signing-key-row.tsx
index 42fdc4d94c6..d6723d1e19b 100644
--- a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/signing-key-row.tsx
+++ b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/signing-key-row.tsx
@@ -4,21 +4,18 @@ import {
CircleArrowDownIcon,
CircleArrowUpIcon,
EyeIcon,
- KeyIcon,
MinusIcon,
MoreVerticalIcon,
ShieldOffIcon,
- TimerIcon,
Trash2Icon,
} from 'lucide-react'
import { motion } from 'motion/react'
import {
- Badge,
- Button,
cn,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
+ DropdownMenuSeparator,
DropdownMenuTrigger,
TableCell,
TableRow,
@@ -27,7 +24,8 @@ import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import { TimestampInfo } from 'ui-patterns/TimestampInfo'
import { AlgorithmHoverCard } from '../algorithm-hover-card'
-import { statusColors, statusLabels } from '../jwt.constants'
+import { statusLabels } from '../jwt.constants'
+import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
import { JWTSigningKey } from '@/data/jwt-signing-keys/jwt-signing-keys-query'
@@ -63,7 +61,7 @@ const LastUsedCell = ({
isLastUsedSupported: boolean
}) => {
const className =
- 'text-right py-2 text-sm text-foreground-light whitespace-nowrap data-[invisible=true]:invisible'
+ 'text-right text-sm text-foreground-light whitespace-nowrap data-[invisible=true]:invisible'
if (!isLastUsedSupported)
return (
@@ -81,6 +79,7 @@ const LastUsedCell = ({
}
if (isError) return <TableCell className={className}>Unable to load</TableCell>
+
if (lastUsedAt === undefined) {
return (
<TableCell className={cn(className, 'text-foreground-lighter')}>No requests in 24h</TableCell>
@@ -126,47 +125,16 @@ export const SigningKeyRow = ({
signingKey.status !== 'in_use' ? 'border-b border-dashed border-border' : 'border-b'
)}
>
- <TableCell className="w-[150px] pr-0 py-2">
- <div className="flex -space-x-px items-center">
- <Badge
- className={cn(
- statusColors[signingKey.status],
- 'rounded-r-none',
- 'gap-2 w-full h-6',
- 'uppercase font-mono',
- 'border-r-0'
- )}
- >
- {signingKey.status === 'standby' ? (
- <TimerIcon className="shrink-0" size={14} />
- ) : (
- <KeyIcon className="shrink-0" size={14} />
- )}
- <span className="truncate text-xs">{statusLabels[signingKey.status]}</span>
- </Badge>
- </div>
- </TableCell>
- <TableCell className="font-mono truncate w-[315px] pl-0 py-2">
- <div className="min-w-0 flex">
- <Badge
- className={cn(
- 'bg-default-200/100 border-foreground-muted',
- 'rounded-l-none',
- 'gap-2 py-2 h-6 min-w-0 overflow-hidden flex items-center flex-1'
- )}
- >
- <span className="truncate flex-1 text-xs" title={signingKey.id}>
- {signingKey.id}
- </span>
- </Badge>
- </div>
+ <TableCell className={cn(signingKey.status !== 'in_use' && 'text-foreground-lighter')}>
+ {statusLabels[signingKey.status]}
</TableCell>
- <TableCell className="truncate py-2">
- <AlgorithmHoverCard
- algorithm={signingKey.algorithm}
- legacy={signingKey.id === legacyKey?.id}
- />
+
+ <TableCell className="font-mono whitespace-nowrap">{signingKey.id}</TableCell>
+
+ <TableCell>
+ <AlgorithmHoverCard algorithm={signingKey.algorithm} />
</TableCell>
+
{isLastUsedVisible && (
<LastUsedCell
lastUsedAt={lastUsedAt}
@@ -175,9 +143,11 @@ export const SigningKeyRow = ({
isLastUsedSupported={signingKey.id !== legacyKey?.id}
/>
)}
+
{!isLastUsedVisible && !hasRotationTimestamp(signingKey.status) && <TableCell />}
+
{hasRotationTimestamp(signingKey.status) && (
- <TableCell className="max-w-[100px] text-right py-2 text-sm text-foreground-light whitespace-nowrap hidden lg:table-cell">
+ <TableCell className="max-w-[100px] text-right text-sm text-foreground-light whitespace-nowrap hidden xl:table-cell">
<TimestampInfo
className="text-sm"
utcTimestamp={signingKey.updated_at}
@@ -185,45 +155,53 @@ export const SigningKeyRow = ({
/>
</TableCell>
)}
- <TableCell className="text-right py-2">
+
+ <TableCell className="text-right">
{(signingKey.status !== 'in_use' || signingKey.algorithm !== 'HS256') && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
- <Button
+ <ButtonTooltip
+ variant="default"
aria-label="More options"
- variant="text"
className="px-1.5"
loading={isLoading}
icon={<MoreVerticalIcon className="size-4" />}
+ tooltip={{ content: { side: 'bottom', text: 'More options' } }}
/>
</DropdownMenuTrigger>
+
<DropdownMenuContent align="end" className="w-52">
{signingKey.algorithm !== 'HS256' && (
<DropdownMenuItem
+ className="gap-x-2"
onSelect={() => {
setSelectedKey(signingKey)
setShownDialog('key-details')
}}
>
- <EyeIcon className="mr-2 size-4" />
+ <EyeIcon size={14} />
View key details
</DropdownMenuItem>
)}
+
+ {signingKey.status !== 'in_use' && signingKey.algorithm !== 'HS256' && (
+ <DropdownMenuSeparator />
+ )}
+
{signingKey.status === 'standby' && (
- <>
- <DropdownMenuItem
- onSelect={() => handlePreviouslyUsedKey(signingKey.id)}
- className="text-destructive"
- >
- <CircleArrowDownIcon className="mr-2 size-4" />
- Move to previously used
- </DropdownMenuItem>
- </>
+ <DropdownMenuItem
+ className="gap-x-2"
+ onSelect={() => handlePreviouslyUsedKey(signingKey.id)}
+ >
+ <CircleArrowDownIcon size={14} />
+ Move to previously used
+ </DropdownMenuItem>
)}
{signingKey.status === 'previously_used' && (
<>
<DropdownMenuItemTooltip
disabled={!!standbyKey}
+ className="gap-x-2"
onSelect={() => handleStandbyKey(signingKey.id)}
tooltip={{
content: {
@@ -234,17 +212,18 @@ export const SigningKeyRow = ({
},
}}
>
- <CircleArrowUpIcon className="mr-2 size-4" />
+ <CircleArrowUpIcon size={14} />
Move to standby key
</DropdownMenuItemTooltip>
+
<DropdownMenuItem
+ className="gap-x-2"
onSelect={() => {
setSelectedKey(signingKey)
setShownDialog('revoke')
}}
- className="text-destructive"
>
- <ShieldOffIcon className="mr-2 size-4" />
+ <ShieldOffIcon size={14} />
Revoke key
</DropdownMenuItem>
</>
@@ -252,6 +231,7 @@ export const SigningKeyRow = ({
{signingKey.status === 'revoked' && (
<>
<DropdownMenuItemTooltip
+ className="gap-x-2"
disabled={!!standbyKey}
onSelect={() => handleStandbyKey(signingKey.id)}
tooltip={{
@@ -263,18 +243,19 @@ export const SigningKeyRow = ({
},
}}
>
- <CircleArrowUpIcon className="mr-2 size-4" />
+ <CircleArrowUpIcon size={14} />
Move to standby key
</DropdownMenuItemTooltip>
+
<DropdownMenuItem
onSelect={() => {
setSelectedKey(signingKey)
setShownDialog('delete')
}}
- className="text-destructive"
+ className="gap-x-2"
disabled={legacyKey?.id === signingKey.id}
>
- <Trash2Icon className="mr-2 size-4" />
+ <Trash2Icon size={14} />
Delete permanently
</DropdownMenuItem>
</>
diff --git a/apps/studio/components/interfaces/JwtSecrets/jwt.constants.ts b/apps/studio/components/interfaces/JwtSecrets/jwt.constants.ts
index ea7724a5895..25514d0f5e0 100644
--- a/apps/studio/components/interfaces/JwtSecrets/jwt.constants.ts
+++ b/apps/studio/components/interfaces/JwtSecrets/jwt.constants.ts
@@ -3,9 +3,9 @@ import { JwtSecretUpdateError, JwtSecretUpdateProgress } from '@supabase/shared-
import { JWTSigningKey } from '@/data/jwt-signing-keys/jwt-signing-keys-query'
export const statusLabels: Record<JWTSigningKey['status'], string> = {
- in_use: 'Current key',
- standby: 'Standby key',
- previously_used: 'Previous key',
+ in_use: 'Current',
+ standby: 'Standby',
+ previously_used: 'Previous',
revoked: 'Revoked',
}