Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Empty Strings as Undefined in Environment Validation #147

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions apps/web/src/env.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lermatroid Ignoring the package-lock.json issue, is this what you are expecting from this issue? Just want to make sure that this is what is the purpose of #72

Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

// Helper function to handle empty strings as undefined
const stringOrUndefined = z
.string()
.refine((val) => val !== "", { message: "Value cannot be an empty string" })
.transform((val) => (val === "" ? undefined : val));

export const env = createEnv({
server: {
CLERK_SECRET_KEY: z.string().min(1),
AWS_SES_ACCESS_KEY: z.string().min(1),
AWS_SES_SECRET_ACCESS_KEY: z.string().min(1),
AWS_REGION: z.string().min(1),
AWS_SES_EMAIL_FROM: z.string().min(1),
INTERNAL_AUTH_KEY: z.string().min(64),
BOT_API_URL: z.string().min(1),
CLERK_SECRET_KEY: stringOrUndefined,
AWS_SES_ACCESS_KEY: stringOrUndefined,
AWS_SES_SECRET_ACCESS_KEY: stringOrUndefined,
AWS_REGION: stringOrUndefined,
AWS_SES_EMAIL_FROM: stringOrUndefined,
INTERNAL_AUTH_KEY: z.string().min(64, {
message: "INTERNAL_AUTH_KEY must be at least 64 characters",
}),
BOT_API_URL: stringOrUndefined,
NODE_ENV: z
.enum(["development", "test", "production"])
.default("development"),
},
client: {
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().min(1),
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: stringOrUndefined,
},
// If you're using Next.js < 13.4.4, you'll need to specify the runtimeEnv manually
// runtimeEnv: {
Expand Down
Loading
Loading