"use client"; import { useState } from "react"; import { useField } from "@payloadcms/ui"; /** * Write-only API key input. * * The `apiKey` field itself has read access denied, which is what keeps the secret * out of the admin form value, REST, GraphQL and populated relationships. The side * effect is that Payload does not render a field you cannot read, so the input lives * here as a `ui` field and writes the hidden value through `useField`. * * Only a *new* value is ever typed: the stored key is never shown, so the field * starts empty on every load and an empty submission leaves the stored key alone * (enforced by the collection's beforeChange). */ export function ApiKeyField() { const { value, setValue } = useField({ path: "apiKey" }); const { value: saved } = useField({ path: "hasApiKey" }); const [reveal, setReveal] = useState(false); const forged = typeof value === "string" ? value : ""; return (
setValue(event.target.value)} style={{ flex: 1, padding: "0.5rem 0.75rem", border: "1px solid var(--theme-elevation-150)", borderRadius: "4px", background: "var(--theme-input-bg)", color: "var(--theme-text)", fontFamily: "monospace", }} />

{saved ? "A key is stored and never displayed. Type a new value to replace it." : "Leave blank to use the UNSLOTH_API_KEY environment variable."}{" "} Blank means unchanged; use Clear API key to delete it.

); }