fix(traefik): allow to save domain without letsencrypt email when the cert is none #542

This commit is contained in:
Mauricio Siu
2024-10-12 16:44:10 -06:00
parent 339697437a
commit 8036455c2d
3 changed files with 29 additions and 9 deletions

View File

@@ -29,11 +29,22 @@ import { useForm } from "react-hook-form";
import { toast } from "sonner"; import { toast } from "sonner";
import { z } from "zod"; import { z } from "zod";
const addServerDomain = z.object({ const addServerDomain = z
domain: z.string().min(1, { message: "URL is required" }), .object({
letsEncryptEmail: z.string().min(1, "Email is required").email(), domain: z.string().min(1, { message: "URL is required" }),
certificateType: z.enum(["letsencrypt", "none"]), letsEncryptEmail: z.string(),
}); certificateType: z.enum(["letsencrypt", "none"]),
})
.superRefine((data, ctx) => {
if (data.certificateType === "letsencrypt" && !data.letsEncryptEmail) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message:
"LetsEncrypt email is required when certificate type is letsencrypt",
path: ["letsEncryptEmail"],
});
}
});
type AddServerDomain = z.infer<typeof addServerDomain>; type AddServerDomain = z.infer<typeof addServerDomain>;

View File

@@ -174,7 +174,9 @@ export const settingsRouter = createTRPCRouter({
} }
const admin = await updateAdmin(ctx.user.authId, { const admin = await updateAdmin(ctx.user.authId, {
host: input.host, host: input.host,
letsEncryptEmail: input.letsEncryptEmail, ...(input.letsEncryptEmail && {
letsEncryptEmail: input.letsEncryptEmail,
}),
certificateType: input.certificateType, certificateType: input.certificateType,
}); });
@@ -186,7 +188,10 @@ export const settingsRouter = createTRPCRouter({
} }
updateServerTraefik(admin, input.host); updateServerTraefik(admin, input.host);
updateLetsEncryptEmail(admin.letsEncryptEmail); if (input.letsEncryptEmail) {
updateLetsEncryptEmail(input.letsEncryptEmail);
}
return admin; return admin;
}), }),
cleanSSHPrivateKey: adminProcedure.mutation(async ({ ctx }) => { cleanSSHPrivateKey: adminProcedure.mutation(async ({ ctx }) => {

View File

@@ -45,6 +45,7 @@ const createSchema = createInsertSchema(admins, {
sshPrivateKey: z.string().optional(), sshPrivateKey: z.string().optional(),
certificateType: z.enum(["letsencrypt", "none"]).default("none"), certificateType: z.enum(["letsencrypt", "none"]).default("none"),
serverIp: z.string().optional(), serverIp: z.string().optional(),
letsEncryptEmail: z.string().optional(),
}); });
export const apiSaveSSHKey = createSchema export const apiSaveSSHKey = createSchema
@@ -55,11 +56,14 @@ export const apiSaveSSHKey = createSchema
export const apiAssignDomain = createSchema export const apiAssignDomain = createSchema
.pick({ .pick({
letsEncryptEmail: true,
host: true, host: true,
certificateType: true, certificateType: true,
letsEncryptEmail: true,
}) })
.required(); .required()
.partial({
letsEncryptEmail: true,
});
export const apiUpdateDockerCleanup = createSchema export const apiUpdateDockerCleanup = createSchema
.pick({ .pick({