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',