"use client"; import axios from "axios"; import { Button } from "@/components/ui/button"; import * as React from 'react'; import { useEffect, useState } from "react"; import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; const ApiKeyPage = () => { const [apiKeyViewable, setApiKeyViewable] = useState(-1) const [apiKeys, setApiKeys] = useState<{ id: string, label: string, userId: string }[]>([]) useEffect(() => { const fetchData = async () => { await axios.get("/api/tokens") .then(d => setApiKeys(d.data ?? [])) .catch(console.error) }; fetchData(); }, []); const onApiKeyAdd = async (label: string) => { await axios.post("/api/token", { label }) .then(d => setApiKeys(apiKeys.concat([d.data]))) .catch(console.error) } const onApiKeyDelete = async (id: string) => { await axios.delete("/api/token/" + id) .then((d) => setApiKeys(apiKeys.filter(k => k.id != d.data.id))) .catch(console.error) } return (
API Keys
A list of your secret API keys. Label Token Action {apiKeys.map((key, index) => ( {key.label} {apiKeyViewable == index ? key.id : "*".repeat(key.id.length)} ))}
); } export default ApiKeyPage;