Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): drop the API key show toggle that revealed nothing

Yudhi Armyndharis013c22d37abf
diff --git a/dashboard/src/pages/ApiKeys.test.ts b/dashboard/src/pages/ApiKeys.test.ts
new file mode 100644
index 000000000..ece08f8d9
--- /dev/null
+++ b/dashboard/src/pages/ApiKeys.test.ts
@@ -0,0 +1,74 @@
+// Render test for the API Keys page under the bare `node --test` runner, on the Templates.test.ts
+// harness. The list endpoint returns only each key's prefix (the plaintext exists once, at creation),
+// so the row offers no control that claims to show the key.
+import '../test-helpers/register-hooks.ts';
+import { test, before, afterEach } from 'node:test';
+import assert from 'node:assert/strict';
+import { createElement } from 'react';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
+
+function jsonResponse(data: unknown, status = 200): Response {
+ return new Response(JSON.stringify(data), { status, headers: { 'Content-Type': 'application/json' } });
+}
+
+function installFetchStub(): void {
+ globalThis.fetch = ((input: RequestInfo | URL): Promise<Response> => {
+ const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
+ const path = url.replace(/^https?:\/\/[^/]+/, '');
+ if (path === '/api/sessions') return Promise.resolve(jsonResponse([]));
+ if (path === '/api/auth/api-keys') {
+ return Promise.resolve(
+ jsonResponse([
+ {
+ id: 'key-1',
+ name: 'billing-bot',
+ keyPrefix: 'owa_k1ab',
+ role: 'operator',
+ isActive: true,
+ usageCount: 0,
+ createdAt: '2026-01-01T00:00:00.000Z',
+ },
+ ]),
+ );
+ }
+ return Promise.resolve(jsonResponse({ message: `unstubbed ${path}` }, 404));
+ }) as typeof fetch;
+}
+
+let rtl: typeof import('@testing-library/react');
+let ApiKeys: (typeof import('./ApiKeys.tsx'))['ApiKeys'];
+let ToastProvider: (typeof import('../components/Toast.tsx'))['ToastProvider'];
+let queryClient: QueryClient | undefined;
+
+before(async () => {
+ const { installJsdomGlobals } = await import('../test-helpers/jsdom.ts');
+ await installJsdomGlobals();
+ installFetchStub();
+ const { i18nReady } = await import('../i18n/index.ts');
+ await i18nReady;
+ rtl = await import('@testing-library/react');
+ ({ ToastProvider } = await import('../components/Toast.tsx'));
+ ({ ApiKeys } = await import('./ApiKeys.tsx'));
+});
+
+afterEach(() => {
+ rtl.cleanup();
+ queryClient?.clear();
+ queryClient = undefined;
+});
+
+test('a key row shows its prefix masked and offers no show/hide toggle', async () => {
+ queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 1_000 } } });
+ rtl.render(
+ createElement(
+ QueryClientProvider,
+ { client: queryClient },
+ createElement(ToastProvider, null, createElement(ApiKeys)),
+ ),
+ );
+ await rtl.screen.findByText('owa_k1ab****');
+ assert.ok(
+ !rtl.screen.queryByRole('button', { name: 'Show API key' }),
+ 'the row offers to show a key it does not have',
+ );
+});
diff --git a/dashboard/src/pages/ApiKeys.tsx b/dashboard/src/pages/ApiKeys.tsx
index bcc2ef65a..e47679740 100644
--- a/dashboard/src/pages/ApiKeys.tsx
+++ b/dashboard/src/pages/ApiKeys.tsx
@@ -14,8 +14,6 @@ import {
Copy,
RefreshCw,
Trash2,
- Eye,
- EyeOff,
Loader2,
Check,
KeyRound,
@@ -72,7 +70,6 @@ export function ApiKeys() {
const updateMutation = useUpdateApiKeyMutation();
const deleteMutation = useDeleteApiKeyMutation();
const revokeMutation = useRevokeApiKeyMutation();
- const [visibleKeys, setVisibleKeys] = useState<Set<string>>(new Set());
const [showModal, setShowModal] = useState(false);
const [newKey, setNewKey] = useState(emptyKeyForm);
const [createdKey, setCreatedKey] = useState<string | null>(null);
@@ -166,15 +163,6 @@ export function ApiKeys() {
setConfirmAction(null);
};
- const toggleKeyVisibility = (id: string) => {
- setVisibleKeys(prev => {
- const next = new Set(prev);
- if (next.has(id)) next.delete(id);
- else next.add(id);
- return next;
- });
- };
-
const handleCopy = async (text: string, id: string) => {
if (await copyToClipboard(text)) {
setCopied(id);
@@ -192,21 +180,12 @@ export function ApiKeys() {
columnHelper.accessor('keyPrefix', {
id: 'key',
header: () => t('apiKeys.columns.key'),
- cell: info => {
- const apiKey = info.row.original;
- return (
- <span className="key-cell">
- <code>{visibleKeys.has(apiKey.id) ? apiKey.keyPrefix + '...' : apiKey.keyPrefix + '****'}</code>
- <button
- className="icon-btn-sm"
- onClick={() => toggleKeyVisibility(apiKey.id)}
- aria-label={visibleKeys.has(apiKey.id) ? t('common.hideApiKey') : t('common.showApiKey')}
- >
- {visibleKeys.has(apiKey.id) ? <EyeOff size={14} /> : <Eye size={14} />}
- </button>
- </span>
- );
- },
+ // The list carries only the prefix: the full key exists once, in the post-creation modal.
+ cell: info => (
+ <span className="key-cell">
+ <code>{info.getValue()}****</code>
+ </span>
+ ),
}),
columnHelper.accessor('role', {
header: () => t('apiKeys.columns.role'),
@@ -282,7 +261,7 @@ export function ApiKeys() {
},
}),
]),
- [visibleKeys, t, sessions],
+ [t, sessions],
);
const table = useTable({