Repository navigation
Expand file tree
/
Copy pathenv.js
More file actions
82 lines (79 loc) · 2.97 KB
/
Copy pathenv.js
File metadata and controls
82 lines (79 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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: {
DATABASE_URL: z
.string()
.url()
.refine(
(str) => !str.includes("YOUR_MYSQL_URL_HERE"),
"You forgot to change the default URL",
),
NODE_ENV: z
.enum(["development", "test", "production"])
.default("development"),
NEXTAUTH_SECRET:
process.env.NODE_ENV === "production"
? z.string()
: z.string().optional(),
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
process.env.VERCEL ? z.string() : z.string().url(),
),
GITHUB_ID: z.string(),
GITHUB_SECRET: z.string(),
// Bedrock + moderation. All optional: deploys without them still validate,
// and the auto-review/moderation features stay gated off when unset.
BEDROCK_REGION: z.string().optional(),
BEDROCK_MODEL_ID: z.string().optional(),
MODERATION_ENABLED: z.enum(["true", "false"]).optional(),
ADMIN_EMAIL: z.string().email().optional(),
// Shared secret for internal cron invocations (e.g. promote-scheduled).
// Optional; the route refuses to run when unset.
CRON_SECRET: z.string().optional(),
},
/**
* 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(),
},
/**
* 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,
NODE_ENV: process.env.NODE_ENV,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
GITHUB_ID: process.env.GITHUB_ID,
GITHUB_SECRET: process.env.GITHUB_SECRET,
GITLAB_ID: process.env.GITLAB_ID,
GITLAB_SECRET: process.env.GITLAB_SECRET,
BEDROCK_REGION: process.env.BEDROCK_REGION,
BEDROCK_MODEL_ID: process.env.BEDROCK_MODEL_ID,
MODERATION_ENABLED: process.env.MODERATION_ENABLED,
ADMIN_EMAIL: process.env.ADMIN_EMAIL,
CRON_SECRET: process.env.CRON_SECRET,
},
/**
* 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,
});