From 102bd04d4c5802a1282236061cbd3d7c7a89e3de Mon Sep 17 00:00:00 2001 From: fuomag9 <1580624+fuomag9@users.noreply.github.com> Date: Fri, 7 Nov 2025 11:14:46 +0100 Subject: [PATCH] Fix auto certificate not showing in GUI when editing proxy host MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When editing a proxy host with certificate_id set to null (auto), the dropdown would not show "Managed by Caddy (Auto)" as selected and it would revert to another certificate. There were two issues: 1. Form submission: Empty string from dropdown was treated as falsy, returning undefined instead of null (means "don't change") 2. Database update: The ?? operator treated null as falsy and fell back to existing value instead of saving null Changes: - app/(dashboard)/proxy-hosts/actions.ts: Check formData.has() and explicitly convert empty string to null for auto mode - src/lib/models/proxy-hosts.ts: Use !== undefined instead of ?? to allow null values to be saved - app/(dashboard)/proxy-hosts/ProxyHostsClient.tsx: Add Certificate column to table showing "Managed by Caddy (Auto)" for auto certs Applied same fixes to access_list_id for consistency. Now when users select "Managed by Caddy (Auto)", it correctly sets certificate_id to null, displays properly on subsequent edits, and shows in the table view. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../proxy-hosts/ProxyHostsClient.tsx | 151 ++++++++++-------- app/(dashboard)/proxy-hosts/actions.ts | 8 +- src/lib/models/proxy-hosts.ts | 4 +- 3 files changed, 90 insertions(+), 73 deletions(-) diff --git a/app/(dashboard)/proxy-hosts/ProxyHostsClient.tsx b/app/(dashboard)/proxy-hosts/ProxyHostsClient.tsx index ec6c9366..d691a0aa 100644 --- a/app/(dashboard)/proxy-hosts/ProxyHostsClient.tsx +++ b/app/(dashboard)/proxy-hosts/ProxyHostsClient.tsx @@ -113,6 +113,7 @@ export default function ProxyHostsClient({ hosts, certificates, accessLists }: P Name Domains Upstreams + Certificate Status Actions @@ -120,79 +121,91 @@ export default function ProxyHostsClient({ hosts, certificates, accessLists }: P {hosts.length === 0 ? ( - + No proxy hosts configured. Click "Create Host" to add one. ) : ( - hosts.map((host) => ( - - - - {host.name} - - - - - {host.domains.slice(0, 2).join(", ")} - {host.domains.length > 2 && ` +${host.domains.length - 2} more`} - - - - - {host.upstreams.slice(0, 2).join(", ")} - {host.upstreams.length > 2 && ` +${host.upstreams.length - 2} more`} - - - - - - - - - setEditHost(host)} - sx={{ - color: "rgba(99, 102, 241, 0.8)", - "&:hover": { bgcolor: "rgba(99, 102, 241, 0.1)" } - }} - > - - - - - setDeleteHost(host)} - sx={{ - color: "rgba(239, 68, 68, 0.8)", - "&:hover": { bgcolor: "rgba(239, 68, 68, 0.1)" } - }} - > - - - - - - - )) + hosts.map((host) => { + const certificate = host.certificate_id + ? certificates.find(c => c.id === host.certificate_id) + : null; + const certName = certificate?.name ?? "Managed by Caddy (Auto)"; + + return ( + + + + {host.name} + + + + + {host.domains.slice(0, 2).join(", ")} + {host.domains.length > 2 && ` +${host.domains.length - 2} more`} + + + + + {host.upstreams.slice(0, 2).join(", ")} + {host.upstreams.length > 2 && ` +${host.upstreams.length - 2} more`} + + + + + {certName} + + + + + + + + + setEditHost(host)} + sx={{ + color: "rgba(99, 102, 241, 0.8)", + "&:hover": { bgcolor: "rgba(99, 102, 241, 0.1)" } + }} + > + + + + + setDeleteHost(host)} + sx={{ + color: "rgba(239, 68, 68, 0.8)", + "&:hover": { bgcolor: "rgba(239, 68, 68, 0.1)" } + }} + > + + + + + + + ); + }) )} diff --git a/app/(dashboard)/proxy-hosts/actions.ts b/app/(dashboard)/proxy-hosts/actions.ts index 5b46cb6a..2c8e0173 100644 --- a/app/(dashboard)/proxy-hosts/actions.ts +++ b/app/(dashboard)/proxy-hosts/actions.ts @@ -120,8 +120,12 @@ export async function updateProxyHostAction( name: formData.get("name") ? String(formData.get("name")) : undefined, domains: formData.get("domains") ? parseCsv(formData.get("domains")) : undefined, upstreams: formData.get("upstreams") ? parseCsv(formData.get("upstreams")) : undefined, - certificate_id: formData.get("certificate_id") ? Number(formData.get("certificate_id")) : undefined, - access_list_id: formData.get("access_list_id") ? Number(formData.get("access_list_id")) : undefined, + certificate_id: formData.has("certificate_id") + ? (formData.get("certificate_id") ? Number(formData.get("certificate_id")) : null) + : undefined, + access_list_id: formData.has("access_list_id") + ? (formData.get("access_list_id") ? Number(formData.get("access_list_id")) : null) + : undefined, hsts_subdomains: boolField("hsts_subdomains"), skip_https_hostname_validation: boolField("skip_https_hostname_validation"), enabled: boolField("enabled"), diff --git a/src/lib/models/proxy-hosts.ts b/src/lib/models/proxy-hosts.ts index 935f9bd3..08f7cd13 100644 --- a/src/lib/models/proxy-hosts.ts +++ b/src/lib/models/proxy-hosts.ts @@ -482,8 +482,8 @@ export async function updateProxyHost(id: number, input: Partial name: input.name ?? existing.name, domains, upstreams, - certificateId: input.certificate_id ?? existing.certificate_id, - accessListId: input.access_list_id ?? existing.access_list_id, + certificateId: input.certificate_id !== undefined ? input.certificate_id : existing.certificate_id, + accessListId: input.access_list_id !== undefined ? input.access_list_id : existing.access_list_id, sslForced: input.ssl_forced ?? existing.ssl_forced, hstsEnabled: input.hsts_enabled ?? existing.hsts_enabled, hstsSubdomains: input.hsts_subdomains ?? existing.hsts_subdomains,