import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Ban, Key, Calendar, User, Zap } from "lucide-react"; import { securityService, type ApiKey } from "@/services"; import { toast } from "sonner"; import { format } from "date-fns"; import type { ApiError } from "@/types/error.types"; import { cn } from "@/lib/utils"; export default function ApiKeysPage() { const queryClient = useQueryClient(); const { data: apiKeys, isLoading } = useQuery({ queryKey: ["admin", "security", "api-keys"], queryFn: () => securityService.getAllApiKeys(), }); const revokeMutation = useMutation({ mutationFn: (id: string) => securityService.revokeApiKey(id), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["admin", "security", "api-keys"], }); toast.success("API access credential revoked"); }, onError: (error) => { const apiError = error as ApiError; toast.error( apiError.response?.data?.message || "Failed to revoke access", ); }, }); return (

API Gateway

Management of system access credentials and authentication tokens.

Credential Registry
{isLoading ? ( ) : apiKeys && apiKeys.length > 0 ? ( apiKeys.map((key: ApiKey) => ( )) ) : ( )}
Key Identifier Operator Last Activity Access Status Actions
Retrieving secure credentials...
{key.name}
{key.userId || "N/A"}
{key.lastUsed ? format(new Date(key.lastUsed), "MMM dd, yyyy") : "Inactive"}
{key.isActive ? "Authorized" : "Deactivated"} {key.isActive && ( )}
No API access credentials defined.
); }