fix: improve domain and letsencrypt email validation

This commit is contained in:
Omar Elshenhabi
2025-09-29 01:15:51 +03:00
parent 0f9505327f
commit 6e86fafa5e

View File

@@ -33,9 +33,19 @@ import {
import { Switch } from "@/components/ui/switch";
import { api } from "@/utils/api";
const hostnameRegex =
/^(?=.{1,253}$)(?!-)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.(?!-)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/;
const addServerDomain = z
.object({
domain: z.string(),
domain: z
.string()
.trim()
.toLowerCase()
.regex(
hostnameRegex,
"Invalid hostname (no http://, no slash, no port).",
),
letsEncryptEmail: z.string(),
https: z.boolean().optional(),
certificateType: z.enum(["letsencrypt", "none", "custom"]),
@@ -48,7 +58,11 @@ const addServerDomain = z
message: "Required",
});
}
if (data.certificateType === "letsencrypt" && !data.letsEncryptEmail) {
if (
data.https &&
data.certificateType === "letsencrypt" &&
!data.letsEncryptEmail
) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: