"use client"; import axios from "axios"; import { Button } from "@/components/ui/button"; import * as React from 'react'; import { ApiKey, User } from "@prisma/client"; import { useEffect, useState } from "react"; import { useSession } from "next-auth/react"; import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; const SettingsPage = () => { const { data: session, status } = useSession(); const [apiKeyViewable, setApiKeyViewable] = useState(0) const [apiKeyChanges, setApiKeyChanges] = useState(0) const [apiKeys, setApiKeys] = useState([]) useEffect(() => { const fetchData = async () => { try { const keys = (await axios.get("/api/tokens")).data ?? {}; setApiKeys(keys) } catch (error) { console.log("ERROR", error) } }; fetchData().catch(console.error); }, [apiKeyChanges]); const onApiKeyAdd = async () => { try { await axios.post("/api/token", { label: "Key label" }); setApiKeyChanges(apiKeyChanges + 1) } catch (error) { console.log("ERROR", error) } } const onApiKeyDelete = async (id: string) => { try { await axios.delete("/api/token/" + id); setApiKeyChanges(apiKeyChanges - 1) } catch (error) { console.log("ERROR", error) } } return (
API Keys
A list of your secret API keys. Label Token View Action {apiKeys.map((key, index) => ( {key.label} {(apiKeyViewable & (1 << index)) > 0 ? key.id : "*".repeat(key.id.length)} ))}
); } export default SettingsPage;