Files
kan/src/env.mjs
2024-11-25 22:39:14 +00:00

54 lines
1.6 KiB
JavaScript

import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";
export const env = createEnv({
/**
* Specify your server-side environment variables schema here. This way you can ensure the app
* isn't built with invalid env vars.
*/
server: {
POSTGRES_URL: z
.string()
.url()
.refine(
(str) => !str.includes("YOUR_PG_URL_HERE"),
"You forgot to change the default URL",
),
NODE_ENV: z
.enum(["development", "test", "production"])
.default("development"),
WEBSITE_URL: z.string().url(),
},
/**
* Specify your client-side environment variables schema here. This way you can ensure the app
* isn't built with invalid env vars. To expose them to the client, prefix them with
* `NEXT_PUBLIC_`.
*/
client: {
NEXT_PUBLIC_SUPABASE_AUTH_COOKIE_NAME: z.string(),
},
/**
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
* middlewares) or client-side so we need to destruct manually.
*/
runtimeEnv: {
POSTGRES_URL: process.env.POSTGRES_URL,
NODE_ENV: process.env.NODE_ENV,
WEBSITE_URL: process.env.WEBSITE_URL,
NEXT_PUBLIC_SUPABASE_AUTH_COOKIE_NAME:
process.env.NEXT_PUBLIC_SUPABASE_AUTH_COOKIE_NAME,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
* useful for Docker builds.
*/
skipValidation: !!process.env.SKIP_ENV_VALIDATION,
/**
* Makes it so that empty strings are treated as undefined. `SOME_VAR: z.string()` and
* `SOME_VAR=''` will throw an error.
*/
emptyStringAsUndefined: true,
});