1import { createEnv } from "@t3-oss/env-nextjs";
2import { z } from "zod";
3
4export const env = createEnv({
5 /**
6 * Specify your server-side environment variables schema here. This way you can ensure the app
7 * isn't built with invalid env vars.
8 */
9 server: {
10 DATABASE_URL: z.string().url(),
11 NODE_ENV: z
12 .enum(["development", "test", "production"])
13 .default("development"),
14 },
15
16 /**
17 * Specify your client-side environment variables schema here. This way you can ensure the app
18 * isn't built with invalid env vars. To expose them to the client, prefix them with
19 * `NEXT_PUBLIC_`.
20 */
21 client: {
22 // NEXT_PUBLIC_CLIENTVAR: z.string(),
23 },
24
25 /**
26 * You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
27 * middlewares) or client-side so we need to destruct manually.
28 */
29 runtimeEnv: {
30 DATABASE_URL: process.env.DATABASE_URL,
31 NODE_ENV: process.env.NODE_ENV,
32 // NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
33 },
34 /**
35 * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
36 * useful for Docker builds.
37 */
38 skipValidation: !!process.env.SKIP_ENV_VALIDATION,
39 /**
40 * Makes it so that empty strings are treated as undefined. `SOME_VAR: z.string()` and
41 * `SOME_VAR=''` will throw an error.
42 */
43 emptyStringAsUndefined: true,
44});