"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Button from "@/components/shared/Button"; import Input from "@/components/shared/Input"; export default function NewAPIKeyPage() { const router = useRouter(); const [name, setName] = useState(""); const [error, setError] = useState(""); const [newKey, setNewKey] = useState(null); const [isSubmitting, setIsSubmitting] = useState(false); async function handleSubmit(e) { e.preventDefault(); setIsSubmitting(true); setError(""); try { const response = await fetch("http://localhost:8080/api-keys", { method: "POST", headers: { Authorization: `Bearer ${localStorage.getItem("token")}`, "Content-Type": "application/json", }, body: JSON.stringify({ name }), }); if (!response.ok) throw new Error("Failed to create API key"); const data = await response.json(); setNewKey(data.key); } catch (error) { setError("Failed to create API key"); console.error("Error:", error); } finally { setIsSubmitting(false); } } return ( <> {newKey ? (
Please copy your API key now. You won't be able to see it again!
{newKey}