import { ArrowRight, ExternalLink, Info, Key, Timer } from 'lucide-react' import { useState } from 'react' import { toast } from 'sonner' import { Badge, Button, Checkbox, cn, DialogDescription, DialogFooter, DialogHeader, DialogSection, DialogSectionSeparator, DialogTitle, Label, Skeleton, } from 'ui' import { algorithmLabels } from '../algorithm-details' import { statusColors } from '../jwt.constants' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import { useEdgeFunctionsQuery } from '@/data/edge-functions/edge-functions-query' import { useJWTSigningKeyUpdateMutation } from '@/data/jwt-signing-keys/jwt-signing-key-update-mutation' import { JWTSigningKey } from '@/data/jwt-signing-keys/jwt-signing-keys-query' export function RotateKeyDialog({ projectRef, standbyKey, inUseKey, onClose, }: { projectRef: string standbyKey: JWTSigningKey inUseKey: JWTSigningKey onClose: () => void }) { const [isStandbyUnderstood, setStandbyUnderstood] = useState(false) const [isPreviouslyUsedUnderstood, setPreviouslyUsedUnderstood] = useState(false) const [isEdgeFunctionsVerifyJWTUnderstood, setEdgeFunctionsVerifyJWTUnderstood] = useState(false) const { data: edgeFunctions, isPending: isLoadingEdgeFunctions } = useEdgeFunctionsQuery({ projectRef, }) const { mutate, isPending: isPendingMutation } = useJWTSigningKeyUpdateMutation({ onSuccess: () => { toast.success('Signing key rotated successfully') onClose() }, onError: (error) => { toast.error(`Failed to rotate signing key: ${error.message}`) }, }) const verifyJWTEdgeFunctions = edgeFunctions?.filter(({ verify_jwt }) => verify_jwt) ?? [] return ( <> Rotate JWT signing key Change the key used by Briven Auth to create new JSON Web Tokens. Non-expired tokens remain valid and accepted!
Standby key
Current key
{algorithmLabels[standbyKey.algorithm]}
Current key
Previous key
{algorithmLabels[inUseKey.algorithm]}
{isLoadingEdgeFunctions ? ( <> ) : ( <>
To proceed please confirm:
{verifyJWTEdgeFunctions.length > 0 && ( )} )}
) }