From 8062d33f358ef77cf0c0eca28850c3a35e134c61 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Fri, 6 Feb 2026 14:19:29 +0100 Subject: [PATCH] fix: Validate server-only environment variables exclusively on the server to prevent browser validation errors. --- lib/env.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/env.ts b/lib/env.ts index 59a3c1c4..ef06ab33 100644 --- a/lib/env.ts +++ b/lib/env.ts @@ -58,8 +58,11 @@ export const envSchema = z const target = data.NEXT_PUBLIC_TARGET || data.TARGET; const isDev = target === 'development' || !target; const isBuildTimeValidation = process.env.SKIP_RUNTIME_ENV_VALIDATION === 'true'; + const isServer = typeof window === 'undefined'; - if (!isDev && !isBuildTimeValidation && !data.MAIL_HOST) { + // Only enforce server-only variables when running on the server. + // In the browser, non-NEXT_PUBLIC_ variables are undefined and should not trigger validation errors. + if (isServer && !isDev && !isBuildTimeValidation && !data.MAIL_HOST) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'MAIL_HOST is required in non-development environments',