Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): store the sign-in API key trimmed
Yudhi Armyndharisb7572a1a5540
diff --git a/dashboard/src/pages/Login.test.ts b/dashboard/src/pages/Login.test.tsindex 6d9e178f4..c7804a54e 100644--- a/dashboard/src/pages/Login.test.ts+++ b/dashboard/src/pages/Login.test.ts@@ -39,6 +39,19 @@ afterEach(() => {rtl.cleanup();});+test('a key pasted with surrounding whitespace is sent and stored trimmed', async () => {+ const { screen, fireEvent, waitFor } = rtl;+ const logins: string[] = [];+ rtl.render(createElement(Login, { onLogin: (key: string) => logins.push(key) }));++ fireEvent.change(screen.getByLabelText('API Key'), { target: { value: ' owa_k1_secret ' } });+ fireEvent.click(screen.getByRole('button', { name: 'Connect' }));++ await waitFor(() => assert.equal(logins.length, 1));+ assert.deepEqual(logins, ['owa_k1_secret']);+ assert.equal(sentKey, 'owa_k1_secret');+});+test('the login form aligns to the document direction, which is set on <html>', () => {const css = readFileSync(fileURLToPath(new URL('./Login.css', import.meta.url)), 'utf8');// i18n sets `dir` on the document element only, so a `[dir]` compound after another selector partdiff --git a/dashboard/src/pages/Login.tsx b/dashboard/src/pages/Login.tsxindex 8b1826923..117596465 100644--- a/dashboard/src/pages/Login.tsx+++ b/dashboard/src/pages/Login.tsx@@ -25,7 +25,9 @@ export function Login({ onLogin }: LoginProps) {const handleSubmit = async (e: React.FormEvent) => {e.preventDefault();- if (!apiKey.trim()) {+ // The stored key is matched against key prefixes elsewhere, so a pasted space must not reach it.+ const key = apiKey.trim();+ if (!key) {setError(t('login.apiKeyRequired'));return;}@@ -37,7 +39,7 @@ export function Login({ onLogin }: LoginProps) {method: 'POST',headers: {'Content-Type': 'application/json',- 'X-API-Key': apiKey,+ 'X-API-Key': key,},});@@ -45,7 +47,7 @@ export function Login({ onLogin }: LoginProps) {// The validate body already carries the key's role — hand it up so the app can set it// directly instead of re-validating the same key a second time.const data: { role?: string; engineType?: string } = await response.json().catch(() => ({}));- onLogin(apiKey, data.role, typeof data.engineType === 'string' ? data.engineType : undefined);+ onLogin(key, data.role, typeof data.engineType === 'string' ? data.engineType : undefined);} else {const errorData = await response.json().catch(() => ({}));setError(errorData.message || t('login.invalidKey'));