-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathenv.ts
83 lines (79 loc) · 2.44 KB
/
env.ts
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
83
import { createEnv } from "@t3-oss/env-nextjs"
import { z } from "zod"
export const env = createEnv({
/**
* Environment variables available on the client (and server).
*
* 💡 You'll get type errors if these are not prefixed with NEXT_PUBLIC_.
*/
client: {
NEXT_PUBLIC_HOST: z.string().url().optional(),
NEXT_PUBLIC_VERCEL_URL: z.string().optional(),
NEXT_PUBLIC_GA_MEASUREMENT_ID: z.string().optional()
},
/**
* Server-side Environment variables, not available on the client. Will throw
* if you access these variables on the client.
*/
server: {
/**
* Database
*/
DATABASE_URL: z.string().url(),
DATABASE_URL_POOLED: z.string().url().optional(),
/**
* Authentication
*/
AUTH_SECRET: z.string(),
AUTH_URL: z.string().url().optional(),
/**
* Vercel-specific environment variables
*/
VERCEL_GIT_COMMIT_SHA: z.string().optional(),
VERCEL_URL: z.string().optional(),
/**
* Email
*/
EMAIL_FROM: z.string(),
POSTMARK_API_KEY: z.string().default("")
},
/**
* Shared between server and client
*/
shared: {
/**
* Node environment
*/
NODE_ENV: z
.enum(["development", "production", "test"])
.default("development")
},
/**
* Due to how Next.js (>= 13.4.4) bundles environment variables on the Client,
* we need to manually destructure them to make sure all are included in
* bundle.
*
* 💡 You'll get type errors if not all variables from `client` are included
* here.
*/
experimental__runtimeEnv: {
NODE_ENV: process.env.NODE_ENV,
NEXT_PUBLIC_HOST: process.env.NEXT_PUBLIC_HOST,
NEXT_PUBLIC_VERCEL_URL: process.env.NEXT_PUBLIC_VERCEL_URL,
NEXT_PUBLIC_GA_MEASUREMENT_ID: process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID
},
/**
* By default, this library will feed the environment variables directly to
* the Zod validator.
*
* This means that if you have an empty string for a value that is supposed
* to be a number (e.g. `PORT=` in a ".env" file), Zod will incorrectly flag
* it as a type mismatch violation. Additionally, if you have an empty string
* for a value that is supposed to be a string with a default value (e.g.
* `DOMAIN=` in an ".env" file), the default value will never be applied.
*
* In order to solve these issues, we recommend that all new projects
* explicitly specify this option as true.
*/
emptyStringAsUndefined: true
})