diff --git a/server/private/routers/loginPage/upsertLoginPageBranding.ts b/server/private/routers/loginPage/upsertLoginPageBranding.ts index 958cdeb43..373f9b3c6 100644 --- a/server/private/routers/loginPage/upsertLoginPageBranding.ts +++ b/server/private/routers/loginPage/upsertLoginPageBranding.ts @@ -33,7 +33,10 @@ const paramsSchema = z.strictObject({ }); const bodySchema = z.strictObject({ - logoUrl: z.string().optional(), + logoUrl: z + .string() + .optional() + .transform((val) => (val === "" ? null : val)), logoWidth: z.coerce.number().min(1), logoHeight: z.coerce.number().min(1), resourceTitle: z.string(), diff --git a/src/components/AuthPageBrandingForm.tsx b/src/components/AuthPageBrandingForm.tsx index b5ededd91..8bc4cc2ca 100644 --- a/src/components/AuthPageBrandingForm.tsx +++ b/src/components/AuthPageBrandingForm.tsx @@ -44,67 +44,11 @@ export type AuthPageCustomizationProps = { }; const AuthPageFormSchema = z.object({ - logoUrl: z.union([ - z.literal(""), - z.string().superRefine(async (urlOrPath, ctx) => { - const parseResult = z.url().safeParse(urlOrPath); - if (!parseResult.success) { - if (build !== "enterprise") { - ctx.addIssue({ - code: "custom", - message: "Must be a valid URL" - }); - return; - } else { - try { - validateLocalPath(urlOrPath); - } catch (error) { - ctx.addIssue({ - code: "custom", - message: - "Must be either a valid image URL or a valid pathname starting with `/` and not containing query parameters, `..` or `*`" - }); - } finally { - return; - } - } - } + logoUrl: z + .string() + .optional() + .transform((val) => (val === "" ? undefined : val)), - try { - const response = await fetch(urlOrPath, { - method: "HEAD" - }).catch(() => { - // If HEAD fails (CORS or method not allowed), try GET - return fetch(urlOrPath, { method: "GET" }); - }); - - if (response.status !== 200) { - ctx.addIssue({ - code: "custom", - message: `Failed to load image. Please check that the URL is accessible.` - }); - return; - } - - const contentType = response.headers.get("content-type") ?? ""; - if (!contentType.startsWith("image/")) { - ctx.addIssue({ - code: "custom", - message: `URL does not point to an image. Please provide a URL to an image file (e.g., .png, .jpg, .svg).` - }); - return; - } - } catch (error) { - let errorMessage = - "Unable to verify image URL. Please check that the URL is accessible and points to an image file."; - - ctx.addIssue({ - code: "custom", - message: errorMessage - }); - } - }) - ]), logoWidth: z.coerce.number().min(1), logoHeight: z.coerce.number().min(1), orgTitle: z.string().optional(),