From 51be6544cd310644cd69b8c1a70e6a2d3e5e1b89 Mon Sep 17 00:00:00 2001 From: Ved Prakash <54140516+thorved@users.noreply.github.com> Date: Wed, 8 Oct 2025 02:16:43 +0530 Subject: [PATCH] Standardizes keyPassword field handling and simplifies auth field logic Standardizes the handling of the `keyPassword` field by converting `key_password` to camelCase and ensuring consistent output while preserving resolved credentials. Removes redundant snake_case fields to avoid duplication. Simplifies UI handling of authentication fields by allowing non-relevant fields to persist, delegating filtering logic to the backend for cleaner and more maintainable code. Improves code clarity and aligns with consistent data handling practices. --- src/backend/database/routes/ssh.ts | 8 ++++++-- .../Apps/Host Manager/HostManagerEditor.tsx | 17 ++--------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/backend/database/routes/ssh.ts b/src/backend/database/routes/ssh.ts index 94407726..da00dfd7 100644 --- a/src/backend/database/routes/ssh.ts +++ b/src/backend/database/routes/ssh.ts @@ -711,7 +711,7 @@ router.get( authType: resolvedHost.authType, password: resolvedHost.password || null, key: resolvedHost.key || null, - key_password: resolvedHost.key_password || null, + keyPassword: resolvedHost.keyPassword || null, keyType: resolvedHost.keyType || null, folder: resolvedHost.folder, tags: @@ -1243,7 +1243,11 @@ async function resolveHostCredentials(host: any): Promise { // Convert snake_case to camelCase for hosts without credentials const result = { ...host }; if (host.key_password !== undefined) { - result.keyPassword = host.key_password; + // Only use the inline key_password if keyPassword hasn't been set by credential resolution + if (result.keyPassword === undefined) { + result.keyPassword = host.key_password; + } + // Always remove the snake_case version to standardize the output delete result.key_password; } return result; diff --git a/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx b/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx index fe0a2c0b..ad8e8d99 100644 --- a/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx +++ b/src/ui/Desktop/Apps/Host Manager/HostManagerEditor.tsx @@ -877,21 +877,8 @@ export function HostManagerEditor({ | "credential"; setAuthTab(newAuthType); form.setValue("authType", newAuthType); - - if (newAuthType === "password") { - form.setValue("key", null); - form.setValue("keyPassword", ""); - form.setValue("keyType", "auto"); - form.setValue("credentialId", null); - } else if (newAuthType === "key") { - form.setValue("password", ""); - form.setValue("credentialId", null); - } else if (newAuthType === "credential") { - form.setValue("password", ""); - form.setValue("key", null); - form.setValue("keyPassword", ""); - form.setValue("keyType", "auto"); - } + // Don't clear other auth fields - let them persist + // The backend will only use the fields relevant to the selected authType }} className="flex-1 flex flex-col h-full min-h-0" >