From 9e8b8dc5a2575f8347d17b8709de69df3878bf66 Mon Sep 17 00:00:00 2001 From: Debanjum Date: Sat, 11 Jan 2025 13:38:39 +0700 Subject: [PATCH] Toggle showing api key on web settings page via a visibility toggle - Background Access to the clipboard API is disabled by certain browsers in non localhost http scenarios for security reasons. So the copy API key button doesn't work when khoj is self-hosted with authentication enabled at a non localhost domain - Change This change enables copying API keys by manual text highlight + copy if copy button is disabled Resolves #1070 --- src/interface/web/app/settings/page.tsx | 32 +++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/interface/web/app/settings/page.tsx b/src/interface/web/app/settings/page.tsx index 20c979a5..5c9b72b3 100644 --- a/src/interface/web/app/settings/page.tsx +++ b/src/interface/web/app/settings/page.tsx @@ -59,6 +59,8 @@ import { Check, CaretDown, Waveform, + EyeSlash, + Eye, } from "@phosphor-icons/react"; import Loading from "../components/loading/loading"; @@ -492,6 +494,7 @@ const useApiKeys = () => { function ApiKeyCard() { const { apiKeys, generateAPIKey, copyAPIKey, deleteAPIKey } = useApiKeys(); + const [visibleApiKeys, setVisibleApiKeys] = useState>(new Set()); const { toast } = useToast(); return ( @@ -521,10 +524,35 @@ function ApiKeyCard() { {key.name} - - {`${key.token.slice(0, 6)}...${key.token.slice(-4)}`} + + {visibleApiKeys.has(key.token) + ? key.token + : `${key.token.slice(0, 6)}...${key.token.slice(-4)}`}
+ {visibleApiKeys.has(key.token) ? ( + + setVisibleApiKeys((prev) => { + const next = new Set(prev); + next.delete(key.token); + return next; + }) + } + /> + ) : ( + + setVisibleApiKeys( + new Set([...visibleApiKeys, key.token]), + ) + } + /> + )}