import { Button } from "../../ui/button" import { useApi } from "../components/context-api" import { createSignal, createResource, For, Show } from "solid-js" import style from "./keys.module.css" export default function Keys() { const api = useApi() const [isCreating, setIsCreating] = createSignal(false) const [showCreateForm, setShowCreateForm] = createSignal(false) const [keyName, setKeyName] = createSignal("") const [keysData, { refetch }] = createResource(async () => { const response = await api.keys.$get() return response.json() }) const handleCreateKey = async () => { if (!keyName().trim()) return try { setIsCreating(true) await api.keys.$post({ json: { name: keyName().trim() }, }) refetch() setKeyName("") setShowCreateForm(false) } catch (error) { console.error("Failed to create API key:", error) } finally { setIsCreating(false) } } const handleDeleteKey = async (keyId: string) => { if (!confirm("Are you sure you want to delete this API key? This action cannot be undone.")) { return } try { await api.keys[":id"].$delete({ param: { id: keyId }, }) refetch() } catch (error) { console.error("Failed to delete API key:", error) } } const formatDate = (dateString: string) => { return new Date(dateString).toLocaleDateString() } const formatKey = (key: string) => { if (key.length <= 11) return key return `${key.slice(0, 7)}...${key.slice(-4)}` } const copyToClipboard = async (text: string) => { try { await navigator.clipboard.writeText(text) } catch (error) { console.error("Failed to copy to clipboard:", error) } } return ( <>
Manage your API keys to access the OpenCode gateway.
Create an API key to access opencode gateway