2023-07-23 14:18:10 +02:00
|
|
|
const { z } = require('zod');
|
|
|
|
|
const { createEnv } = require('@t3-oss/env-nextjs');
|
|
|
|
|
|
2023-07-29 14:30:19 +02:00
|
|
|
const portSchema = z.string().regex(/\d+/).transform(Number).optional();
|
|
|
|
|
const envSchema = z.enum(['development', 'test', 'production']);
|
2023-07-23 14:18:10 +02:00
|
|
|
|
|
|
|
|
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: {
|
|
|
|
|
DATABASE_URL: z.string().url(),
|
|
|
|
|
NEXTAUTH_SECRET:
|
2023-07-29 14:30:19 +02:00
|
|
|
process.env.NODE_ENV === 'production' ? z.string().min(1) : z.string().min(1).optional(),
|
2023-07-23 14:18:10 +02:00
|
|
|
NEXTAUTH_URL: z.preprocess(
|
|
|
|
|
// This makes Vercel deployments not fail if you don't set NEXTAUTH_URL
|
|
|
|
|
// Since NextAuth.js automatically uses the VERCEL_URL if present.
|
|
|
|
|
(str) => process.env.VERCEL_URL ?? str,
|
|
|
|
|
// VERCEL_URL doesn't include `https` so it cant be validated as a URL
|
2023-07-29 14:30:19 +02:00
|
|
|
process.env.VERCEL ? z.string().min(1) : z.string().url()
|
2023-07-23 14:18:10 +02:00
|
|
|
),
|
|
|
|
|
DOCKER_HOST: z.string().optional(),
|
2023-08-06 14:12:39 +02:00
|
|
|
DOCKER_PORT: portSchema,
|
2023-07-23 14:18:10 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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_CLIENTVAR: z.string().min(1),
|
2023-07-29 14:30:19 +02:00
|
|
|
NEXT_PUBLIC_DEFAULT_COLOR_SCHEME: z.enum(['light', 'dark']).optional().default('light'),
|
2023-07-23 14:18:10 +02:00
|
|
|
NEXT_PUBLIC_PORT: portSchema,
|
2023-07-29 14:30:19 +02:00
|
|
|
NEXT_PUBLIC_NODE_ENV: envSchema,
|
2023-07-31 23:51:54 +02:00
|
|
|
NEXT_PUBLIC_DOCKER_ENABLED: z.boolean().optional().default(false),
|
2023-07-23 14:18:10 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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: {
|
|
|
|
|
DATABASE_URL: process.env.DATABASE_URL,
|
|
|
|
|
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
|
|
|
|
|
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
|
|
|
|
|
DOCKER_HOST: process.env.DOCKER_HOST,
|
|
|
|
|
DOCKER_PORT: process.env.DOCKER_PORT,
|
|
|
|
|
VERCEL_URL: process.env.VERCEL_URL,
|
2023-07-29 14:30:19 +02:00
|
|
|
NEXT_PUBLIC_DEFAULT_COLOR_SCHEME: process.env.DEFAULT_COLOR_SCHEME,
|
2023-07-23 14:18:10 +02:00
|
|
|
NEXT_PUBLIC_PORT: process.env.PORT,
|
2023-07-29 14:30:19 +02:00
|
|
|
NEXT_PUBLIC_NODE_ENV: process.env.NODE_ENV,
|
2023-07-31 23:51:54 +02:00
|
|
|
NEXT_PUBLIC_DOCKER_ENABLED: !!process.env.DOCKER_HOST,
|
2023-07-23 14:18:10 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
2023-07-29 14:30:19 +02:00
|
|
|
env,
|
|
|
|
|
};
|