summaryrefslogtreecommitdiff
path: root/src/env.js
diff options
context:
space:
mode:
authorBertrand Yuan <bert.yuan@outlook.com>2025-12-15 23:48:10 +0800
committerBertrand Yuan <bert.yuan@outlook.com>2025-12-15 23:48:10 +0800
commit5b7ccf0b671e2999b62befc729a3e517a0433728 (patch)
tree8bf476dc7c75914c221042546840dc76267366df /src/env.js
initial commit -- the front-end prototype
The initial code is base on Anirudh's work. More to see at: https://github.com/techwithanirudh/shadcn-blog Therefore, the code in this commit is under MIT license.
Diffstat (limited to 'src/env.js')
-rw-r--r--src/env.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/env.js b/src/env.js
new file mode 100644
index 0000000..91dc423
--- /dev/null
+++ b/src/env.js
@@ -0,0 +1,74 @@
+import { createEnv } from '@t3-oss/env-nextjs';
+import { z } from 'zod';
+
+export const env = createEnv({
+ /**
+ * Specify your shared environment variables schema here. This way you can ensure the app
+ * isn't built with invalid env vars.
+ */
+ shared: {
+ NODE_ENV: z
+ .enum(['development', 'production', 'test'])
+ .default('development'),
+ },
+
+ /**
+ * Specify your server-side environment variables schema here. This way you can ensure the app
+ * isn't built with invalid env vars.
+ */
+ server: {
+ // Database
+ DATABASE_URL: z.string().url(),
+ // Resend
+ RESEND_API_KEY: z.string().min(1).startsWith('re_'),
+ RESEND_AUDIENCE_ID: z.string().min(1),
+ EMAIL_FROM: z.string().email(),
+ // Authentication
+ BETTER_AUTH_SECRET:
+ process.env.NODE_ENV === 'production'
+ ? z.string().min(1)
+ : z.string().min(1).optional(),
+ BETTER_AUTH_URL: z.string().min(1).optional(),
+ // Google
+ GOOGLE_CLIENT_ID: z.string().min(1),
+ GOOGLE_CLIENT_SECRET: z.string().min(1),
+ // Github
+ GITHUB_CLIENT_ID: z.string().min(1),
+ GITHUB_CLIENT_SECRET: z.string().min(1),
+ NODE_ENV: z
+ .enum(['development', 'test', 'production'])
+ .default('development'),
+ },
+
+ /**
+ * 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: {
+ // Analytics
+ NEXT_PUBLIC_UMAMI_URL: z.string().url().optional(),
+ NEXT_PUBLIC_UMAMI_WEBSITE_ID: z.string().uuid().optional(),
+ },
+
+ /**
+ * 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.
+ */
+ experimental__runtimeEnv: {
+ NODE_ENV: process.env.NODE_ENV,
+
+ NEXT_PUBLIC_UMAMI_URL: process.env.NEXT_PUBLIC_UMAMI_URL,
+ NEXT_PUBLIC_UMAMI_WEBSITE_ID: process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID,
+ },
+ /**
+ * 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,
+});